Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your <strong>background is only one page and acts like a local server</strong> that can send and receive data between the <code>content_scripts</code> and <code>default_popup</code> or other extension pages.</p> <p>For anyone starting out, look at each example's manifest version, which is defined in manifest.json. Version 2 has stricter security policies and inline javascript is invalid so copying sample v1 code and pasting it into background.html will not work anymore. All scripts need to be in an external file that can be included in an HTML file using the <code>src</code> attribute like <code>&lt;script src="main.js"&gt;&lt;/script&gt;</code></p> <p>My understanding is that you have four commonly used components for a basic extension:</p> <ol> <li><p>DOM of the tab being viewed which can <strong>only be accessed by <code>content_scripts</code></strong></p></li> <li><p><strong>content_scripts</strong> is an array of javascript files identified in manifest.json that are sequentially injected directly into the tab's DOM. Apparently the JS variables and functions from the tab and your content_scripts cannot interact.</p></li> <li><p><strong>One background HTML page</strong> which Chrome either generates by concatenating an array of scripts <strong>OR</strong> is defined as one page, commonly named background.html.</p></li> <li><p><code>{"browser_action" : {"default_popup" : "popup.html"}}</code> is an optional user interface defined in manifest.json that is displayed when someone clicks your extension icon. The popup has no way to reach the tab's DOM so if the tab's content matters then it must be requested using Chrome messages like <code>chrome.extension.sendMessage</code></p></li> </ol> <p>Your background is defined either as one or more <code>scripts</code>: </p> <pre><code> "background": { "scripts": ["background.js"] }, </code></pre> <p>Or as a <code>page</code>:</p> <pre><code> "background": { "page": "background.html" }, </code></pre> <p>If you want to find out what is happening inside of the background then you can use console.log but in order to inspect the output you have to launch the inspector from the Extensions page. You can even see that the background file is always named "_generated_background_page.html".</p> <p><img src="https://i.stack.imgur.com/MSVxw.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload