background.js Uncaught TypeError: Cannot read property 'xxx' of undefined
来源:互联网 发布:辽宁省软件协会 编辑:程序博客网 时间:2024/05/17 18:26
chrome extensions 开发过程中 background.js 调用chrom.** js的过程中经常遇到
background.js:24 Uncaught TypeError: Cannot read property 'onClicked' of undefined at background.js:24
chrome.browserAction.onClicked.addListener(function(tab) {alert("hello world");
解决办法
https://developer.chrome.com/extensions/browserAction#event-onClicked
onClicked
Fired when a browser action icon is clicked. This event will not fire if the browser action has a popup.
addListener
chrome.browserAction.onClicked.addListener(function callback)
The callback parameter should be a function that looks like this:
function( tabs.Tab tab) {...};
tabs.Tabtab "browser_action": { "default_icon": "image/icon.png" , "default_title": "default title", "default_popup": "popup.html" },去掉default_popup 就可以了
第二个错误
_generated_background_page.html:1 Error in event handler for runtime.onInstalled: TypeError: Cannot read property 'onPageChanged' of undefined at chrome-extension://ncbflhomeaakikacjdicoamijeabneml/js/background.js:8:27
chrome.runtime.onInstalled.addListener(function() {// Replace all rules ...chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
解决办法
https://developer.chrome.com/extensions/declarativeContent
chrome.declarativeContent
Description:Use thechrome.declarativeContent
API to take actions depending on the content of a page, without requiring permission to read the page's content. Availability:Since Chrome 33.
Permissions:"declarativeContent" 查看了一下 declarativeContent的用法, 发现调用相关的js方法 需要declarativeContent权限
至此问题解决
总结: 遇到这种错误一般都是相关属性使用错误
主要参考官方文档
https://developer.chrome.com/extensions 官方文档首页
https://developer.chrome.com/extensions/samples 官方demo
0 0
- background.js Uncaught TypeError: Cannot read property 'xxx' of undefined
- Extjs4---Uncaught TypeError: Cannot read property ‘items’ of undefined
- 【StackFlow】Uncaught TypeError: Cannot read property 'pageCount' of undefined
- Ckeditor: Uncaught TypeError: Cannot read property 'keyCode' of undefined 解决方法
- Uncaught TypeError: Cannot read property 'msie' of undefined问题解决方案
- Uncaught TypeError: Cannot read property 'options' of undefined 错误
- Uncaught TypeError: Cannot read property 'length' of undefined
- 错误:Uncaught TypeError: Cannot read property 'WebSocket' of undefined
- Uncaught TypeError: Cannot read property 'value' of undefined
- Uncaught TypeError: Cannot read property 'plugin' of undefined
- react Uncaught TypeError: Cannot read property 'title' of undefined
- Uncaught TypeError: Cannot read property 'width' of undefined
- Uncaught TypeError: Cannot read property 'substring' of undefined
- Uncaught TypeError: Cannot read property 'PRINT_INIT' of undefined user:100
- Uncaught TypeError: Cannot read property 'substring' of undefined
- extjs4:Uncaught TypeError: Cannot read property 'processed' of undefined
- Datatables 之Uncaught TypeError: Cannot read property 'mData' of undefined
- Uncaught TypeError: Cannot read property 'decimalSeparator' of undefined
- Android BASE64Encoder不能用的问题
- 采用imagecropper.jss+canvas实现裁剪后多尺寸的图像预览
- Android使用回调接口
- unity,第一个游戏(三,游戏后期美化)
- Java中List、Map、Set的遍历方式
- background.js Uncaught TypeError: Cannot read property 'xxx' of undefined
- poj3087 Shuffle'm Up 模拟
- 使用simhash算法对网页去重
- 前端利器:SASS基础与Compass入门
- sicily Binary Search 二分查找
- 转发和重定向的区别
- http://www.cnblogs.com/ifantastic/p/3185665.html
- Ubuntu14.04系统安装Python+机器学习(二)
- spark 存储json数据遇到问题——json4s使用(一)