如何调试谷歌浏览器后台脚本? [英] How to debug Google Chrome background script?

查看:170
本文介绍了如何调试谷歌浏览器后台脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很简单的扩展:

的manifest.json

manifest.json

{
  "name": "historyCleaner",
  "version": "0.1.1",
  "manifest_version": 1,
  "description": "This is my first Chrome extension",
  "background": {
    "scripts": ["cleaner.js"]
  }, 
  "permissions": [
    "history"
  ]
}

cleaner.js

cleaner.js

chrome.history.onVisited.addListener(function(HistoryItem result) {

  console.log("it works!");
  alert("it works!");

});

我在谷歌浏览器加载它,它打开并......这是行不通的。它不记录在控制台任何东西,它不会警告任何事情,更糟糕的是,我不能在开发者的工具脚本选项卡中找到它。我如何才能找到它为什么不工作呢?

I've loaded it in Google Chrome, it is turned on and... it doesn't work. It doesn't log anything in console, it doesn't alert anything and what is worse, I can't find it in developers tools "Scripts" tab. How can I find why it doesn't work?

//修改

我已经改变了的manifest.json这一个:

I've changed manifest.json to this one:

{
  "name": "historyCleaner",
  "version": "0.1.5",
  "manifest_version": 1,
  "description": "This is my first Chrome extension",
  "background_page": "background.html",
  "permissions": [
    "history",
    "background"
  ]
}

而在background.html内嵌的JavaScript

And embeded JavaScript in background.html

推荐答案

和也,如果你的的console.log(它的作品!); 显示不出来,那么这意味着 chrome.history.onVisited 还没有被解雇。

and also if your console.log("it works!"); does not show up, then that's mean chrome.history.onVisited is not fired yet.

PS:对于函数(HistoryItem结果),您可能希望将其更改为功能(结果)

ps: For function(HistoryItem result), you may want to change it to function(result).

这篇关于如何调试谷歌浏览器后台脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆