Examples of using Background scripts in English and their translations into Japanese
{-}
-
Colloquial
-
Ecclesiastic
-
Computer
-
Programming
However, it runs in a different scope than your background scripts.
Web content Background scripts do not get direct access to web pages.
For background scripts, any element can be set to content editable mode.
Here is where you include your so-called background scripts, which control the extension's background process.
Background scripts can access all the WebExtension JavaScript APIs, but they can't directly access the content of web pages.
JavaScript running in the popupgets access to all the same WebExtension APIs as your background scripts, but its global context is the popup, not the current page displayed in the browser.
WebExtension APIs Background scripts can use any of the WebExtension APIs in the script, as long as their extension has the necessary permissions.
Content scripts can only access a small subset of the WebExtension APIs,but they can communicate with background scripts using a messaging system, and thereby indirectly access the WebExtension APIs.
Cross-origin access Background scripts can make XHR requests to any hosts for which they have host permissions.
Using manifest. json, you specify basic metadata about your extension such as the name and version, and can also specify aspects of your extension's functionality,such as background scripts, content scripts, and browser actions.
Exchange messages with their background scripts and can in this way indirectly access all the WebExtension APIs.
If you want to share data orfunctions between the JavaScript on your options page and your background script(s), you can do so directly by obtaining a reference to the Window of your background scripts by using extension.
Background scripts Extensions often need to maintain long-term state or perform long-term operations independently of the lifetime of any particular web page or browser window.
JavaScript APIs- Mozilla|MDN JavaScript APIs for WebExtensions can be used inside the extension's background scripts and in any other documents bundled with the extension, including browser action or page action popups, sidebars, options pages, or new tab pages.
Background scripts are the place to put code that needs to maintain long-term state, or perform long-term operations, independently of the lifetime of any particular web pages or browser windows.
There are two basic patterns for communicating between the background scripts and content scripts: you can send one-off messages, with an optional response, or you can set up a longer-lived connection between the two sides, and use that connection to exchange messages.
Communicating with background scripts Although content scripts can't directly use most of the WebExtension APIs, they can communicate with the extension's background scripts using the messaging APIs, and can therefore indirectly access all the same APIs that the background scripts can.
Content security policy Background scripts are restricted from certain potentially dangerous operations, like the use of eval(), through a Content Security Policy.
The latter(or runtime. Port equivalents)can also be used to share options between your background script(s) and your content scripts. .
Connection-based messaging Sending one-off messages canget cumbersome if you are exchanging a lot of messages between a background script and a content script. .
One-off messages To send one-off messages, with an optional response, you can use the following APIs:In content script In background script Send a message For example, here's a content script which listens for click events in the web page.
However, they do also getaccess to all the same privileged WebExtension APIs as your background script.
JavaScript running in the page gets access to the same privileged"browser.*" APIs as the extension's background script.
All of these are a type of Extension pages, and unlike a normal web page,your JavaScript can use all the same privileged WebExtension APIs as your background script.
Using Web Workers- Web APIs| MDN Web Workers are asimple means for web content to run scripts in background threads.