chrome.tabs.create提供了一个错误 - “Uncaught TypeError:无法调用未定义的方法'create' [英] chrome.tabs.create is giving an error - "Uncaught TypeError: Cannot call method 'create' of undefined"

查看:231
本文介绍了chrome.tabs.create提供了一个错误 - “Uncaught TypeError:无法调用未定义的方法'create'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的manifest.json包含

 content_scripts:[
{
matches: [http://www.facebook.com/*\",\"https://www.facebook.com/*],
js:[js / jquery-1.7.2.min。 js,js / jquery.livequery.min.js,js / script.js]
}
]

和script.js的内容是

$ $ p $ $ $ $ $#FB_HiddenContainer ).livequery(function(){
chrome.tabs.create({url:http://www.google.com});
});

当我打开Facebook时,控制台报告错误

Uncaught TypeError:无法调用未定义的方法'create'


$ b chrome-扩展名://whateveristhisweirdcode/js/script.js:2

如何让它打开新标签?内容脚本不能访问大多数扩展API;内容脚本不能访问大多数扩展API;内容脚本不能访问大多数扩展API;只有在内容脚本文档中列出的才有效。请改用 window.open http://www.google.com )(是的,这个确实在Chrome中创建了一个新标签;不, Chrome浏览器中的任何用户设置都不会改变这一点)。如果您需要更多的扩展API访问权限,则可以使用消息传递使您的活动页面代表内容脚本处理事情。


My manifest.json contains

"content_scripts": [
  {
  "matches": ["http://www.facebook.com/*","https://www.facebook.com/*"],
   "js": ["js/jquery-1.7.2.min.js", "js/jquery.livequery.min.js", "js/script.js"]
  }
]

and the contents of script.js are

$("#FB_HiddenContainer").livequery(function(){
   chrome.tabs.create({"url":"http://www.google.com"});
});

When i open facebook, console reports an error

Uncaught TypeError: Cannot call method 'create' of undefined

at

chrome-extension://whateveristhisweirdcode/js/script.js:2

How can i make it open a new tab??

解决方案

Content scripts can't access most extension APIs; only those listed in the content scripts doc will work. Instead, use window.open("http://www.google.com") (yes, this does create a new tab in Chrome; no, there aren't any user settings in Chrome that would change that). If you need more access to the extension APIs, you can use message passing to make your event page do things on behalf of the content script.

这篇关于chrome.tabs.create提供了一个错误 - “Uncaught TypeError:无法调用未定义的方法'create'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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