Building a Chrome Extension
What does _ precursor to name mean?
Private function.
How to send data from DOM to background script once?
Use chrome.extension.sendMessage(type, data) in your content script.
Content Script
manifest.json section for scripts which access the current page's DOM. Will execute with each page refresh.
manifest.json: required properties
name version - for auto-update system manifest_version - should be 2
manifest.json
Specifies all the special permissions required by the extension.
manifest.json: how to make an "event" background page
"background": { "scripts": ["background.js"], "persistent": false/true }
Get current page URL
window.location.href
XHR
Another name for AJAX. Used to safely make requests across domains.
manifest.json: background
Files needed by the background tab.
manifest.json: content_scripts
Scripts which will be inserted into every page visited. Also includes CSS files.
How to add images to an extension?
Add their path to the "web_accessible_resources" array in the manifest, and append "chrome-extension://__MSG_@@extension_id__/" the URL when calling.
What type of browser object are Chrome Extensions?
Hidden background tabs.
Can a Content Script access the extension's background page?
No - Think of a content script as part of that loaded page, not as part of the extension it was packaged with (its parent extension).
How to send data from DOM to background script ongoing?
Open a port on content side with chrome.runtime.connect({channel name}), and background with chrome.runtime.onConnect.addListener(onConnectFunc(portName))