Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chrome.tabs.create - callback function never called

I want to create a new tab using Chrome Extension and when tab is loaded to show tab.id. Page is loaded but callback function is not worked (alert with tab.id is now showed).

The background.js file:

chrome.tabs.create({'url': 'http://www.google.com'}, function(tab){ alert(tab.id) })

The manifest.json file:

 {
     "name": "Test",
     "version": "1.0",
     "description": "Test plugin",
     "browser_action": {
         "default_popup": "popup.html",
         "default_icon":"icon.png"
     },
     "background": {
         "scripts": ["background.js"]
     },
     "manifest_version":2,
     "permissions": [
          "tabs",
          "http://*.facebook.com/*",
          "http://*.google.com/*",
          "storage"
     ]
}

The popup.html file:

<html>
  <head>
    <title>Test tabs</title>
  </head>
  <body>
    <script type="text/javascript" src=/background.js"></script>
  </body>
</html>

What can be a problem?

like image 435
shtkuh Avatar asked Sep 03 '26 21:09

shtkuh


1 Answers

Your code must be located in background pages.

This is in the manifest.json file:

"background" : {"scripts" : ["background_script.js"] }

or

"background" : {"page" : "background_page.html" }

You need to use absolute path when you referring to the file inside background page:

<script type="text/javascript" src="/background.js"></script>
like image 117
P̲̳x͓L̳ Avatar answered Sep 05 '26 10:09

P̲̳x͓L̳



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!