繁体   English   中英

无法读取未定义的属性“onBeforeNavigate”(Chrome 扩展)

[英]Cannot read property 'onBeforeNavigate' of undefined (Chrome Extension)

如果“onBeforeNavigate”上的操作发生,我只想触发扩展。 但是无缘无故的扩展总是会引发这个错误:

Cannot read property 'onBeforeNavigate' of undefined在此行chrome.webNavigation.onBeforeNavigate.addListener(setProxy);

到目前为止,这是我的代码:

popup.js

function setProxy(details){
    console.log("Got fired!\n");
}

chrome.webNavigation.onBeforeNavigate.addListener(setProxy);

manifest.json

{
  "manifest_version": 2,

  "name": "Proxy Changer",
  "description": "This extension Changes the Proxy settings every time you load a website",
  "version": "1.0",

  "browser_action": {
    "default_icon": "icon.png"
  },

  "permissions": [
    "activeTab",
    "webRequest",
    "notifications",
    "debugger",
    "background",
    "management",
    "https://ajax.googleapis.com/",
    "<all_urls>",
    "webRequestBlocking"
  ],

  "background": {
    "scripts": ["popup.js"],
    "persistent": true,
    "js": ["jQuery.js", "popup.js"]
  }
}

我不想说我对 Google Chrome 扩展程序 API 很陌生,但对我来说,扩展程序 API 不起作用......我不知道我做错了什么......我已经看过视频但仍然是同样的错误...... .

我会很感激你的帮助。 谢谢你和亲切的问候!

只需将“webNavigation”权限添加到 Manifest.json

{ "name": "我的扩展", ... "permissions": [ "webNavigation" ], ... }

请参阅文档https://developer.chrome.com/docs/extensions/reference/webNavigation/#event-onCreatedNavigationTarget

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM