Reputation: 391
I recently started learning about Chrome Extensions and was taking a look at the sample code to get a feel for how all the different parts fit together. I see that the logic behind the extensions are handled mostly in the background pages, but in looking at the following sample code I noticed something peculiar.
{
"name": "Notification Demo",
"version": "1",
"description":
"Shows off desktop notifications, which are \"toast\" windows that pop up on the desktop.",
"icons": {"16": "16.png", "48": "48.png", "128": "128.png"},
"permissions": ["tabs", "notifications"],
"options_page": "options.html",
"background": { "scripts": ["background.js"] },
"content_security_policy": "script-src 'self'; img-src 'self'"
}
There's no "background_page" here but instead a "background" element. I know there's a setting in the "permissions" that allows chrome to run in the background even when it isn't open but this appears to be something different. It seems like it's possible to use a background script instead of a page but when I try to search for information about this I come up with nothing. Has anyone seen or used this before and can you give a brief description of what the advantage would be to using a background script over a background page?
Upvotes: 4
Views: 4731
Reputation: 47913
This is part of the security work that will not allow execution of inline JavaScript. Instead of having a background_page
that only loads a background_script
, use a separate file to allow loading the JS directly. Since background code has no UI, HTML really isn't needed. This looks to be recent work and has not yet been documented.
Upvotes: 4
Reputation: 1151
You can see this implementation in action in Google's sample code for the browserAction function:
Check out make_bg_red in particular.
Upvotes: 2