Disclosure under expansion



  • The only function is to remove the message under the expansion phase. It happens in different ways:

    1. Browser launch
    2. Attack on the very icon.
    3. on a page

    The first is working, and the following are making a mistake:

    Uncaught TypeError: Cannot read property 'setBadgeText' of undefined
    

    Please help. Thanks.

    [ manifest.json ]

    {
        "manifest_version": 2,
    
    "name": "name",
    "version": "1.0.0.0",
    "description": "description",
    
    "permissions": ["http://google.ru/*", "http://yandex.ru/*"],
    
    "browser_action": { "default_popup": "popup.html" },
    
    "background": { "page": "popup.html" },
    
    "content_scripts":[{
        "matches": ["https://www.google.ru/*", "https://yandex.ru/*"],
        "js": [ "script.js" ]
    }]
    

    }

    [ popup.html ]

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <style>html { width: 500px; height: 300px; }</style>
    <script type="text/javascript" src="script.js"></script>
    </head>

    <body>
    <div id="wrapper">
    <div id="header"></div>
    <div id="content"></div>
    <div id="footer"></div>
    </div>
    </body>
    </html>

    [ script.js ]

    var amount = Math.floor(Math.random() * 100);
    alert(amount);
    chrome.browserAction.setBadgeText({ text: amount.toString() });



  • The first works, the next one makes a mistake.

    When applied to the icon, values change as must and error occurs in the third option, as a result of the challenge chrome.browserAction.setBadgeText of content_scriptsbecause content_scripts

    "content_scripts":[{
        "matches": ["https://www.google.ru/*", "https://yandex.ru/*"],
        "js": [ "script.js" ]
    }]
    

    without access chrome.* api.

    However, content scripts have some limitations. They cannot:

    • Use chrome.* APIs, with the exception of:
      • extension ( getURL , inIncognitoContext , lastError , onRequest , sendRequest )
      • i18n
      • runtime ( connect , getManifest , getURL , id , onConnect , onMessage , sendMessage )
      • storage
    • Use variables or functions defined by their extension's pages
    • Use variables or functions defined by web pages or by other content scripts

    The error will only come to the consolation of the pages that meet matches

    These actions need to be implemented. background♪ The first two ways work because of what's in popup.html connected scripts.jsand he has access to the right function.

    If values need to change depending on URL♪ You can use the event ♪ chrome.tabs.onUpdated

    It's an event that works at the time the deposit is updated, callbackEvents can be collected and tracked URL, it may carry out the necessary actions to set the necessary values.

    https://developer.chrome.com/extensions/content_scripts https://developer.chrome.com/extensions/tabs https://developer.chrome.com/extensions/tabs#event-on..




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2