Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chrome.tabs.create is giving an error - "Uncaught TypeError: Cannot call method 'create' of undefined"

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??

like image 445
Shikhar Sharma Avatar asked May 19 '12 16:05

Shikhar Sharma


1 Answers

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.

like image 154
Pixievolt No. 1 Avatar answered Oct 06 '22 01:10

Pixievolt No. 1