Chrome extension to redirect tab to my page

后端 未结 3 972
醉话见心
醉话见心 2021-01-01 06:40

I am new to chrome extensions and I am having trouble while writing my first extension for chrome. What I am trying to do is detect the new tab action and redirect to a pre-

3条回答
  •  梦毁少年i
    2021-01-01 07:09

    With the new chrome extensions you should not put any script code in the background page.

    Inline scripts and event handlers disallowed

    Due to the use of Content Security Policy, you can no longer use tags that are inline with the HTML content. These must be moved to external JS files. In addition, inline event handlers are also not supported. For example, suppose you had the following code in your extension:

    https://developer.chrome.com/extensions/tut_migration_to_manifest_v2.html#inline_scripts

    What you should do is move your code to a js file, either set the manifest background property to a js file or have a background page that links to an external js file and put all you js code there...

    Try using the background property: http://developer.chrome.com/extensions/background_pages.html

    1)basically add to your manifest a background script (you do not need the background page for your extension right now)

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

    2) Then add a a background.js to your extension directory and put all your js code there..

    Then try again, and see if the extension works :)

    3) remove all html from the js file and put just you js in the background.js

    chrome.browserAction.onClicked.addListener(function(tab){
                var action_url = "www.xyz.com"
                chrome.tabs.create({ url: action_url });
        }
    

提交回复
热议问题