Chrome extensions (and/or tampermonkey scripts) not running on certain websites (like gmail) - google-chrome-extension

I have a very simple chrome extension that refuses to run on some sites like https://mail.google.com. It runs fine on other sites which makes me think something is limiting extensions/scripts from running on some sites. The sample case is quite simple and listed below.
With this sample case I see "Hello world" in the developer console when I navigate to https://about.me. I also see the extension in the Developer Console's Execution Context Selector. However, when I navigate to https://mail.google.com I don't see the log entry or the extension in the Execution Context Selector.
I have tried something similar with tampermonkey and am not seeing that script run on gmail either. Thanks!
manifest.json:
{
"manifest_version": 2,
"name": "Gmail extension test",
"version": "0.1.9",
"description": "Try running inside gmail page",
"content_scripts": [{
"all_frames": true,
"js": ["content.js"],
"matches": [
"https://mail.google.com/*",
"https://about.me/*",
"http://*/*",
"https://*/*"
]
}]
}
content.js:
console.warn("Hello world");
Environment:
Chrome 66.0.3359.117
macOS 10.13.3 (17D102)

As #wOxxOm suggested. I tracked down the problem to the fact that my company has a Chrome policy set against running extensions on the google.com domain. I had no warning entries in the Developer Console or the macOS Console, I just tracked down other folks complaining about in an internal forum.
The policy that applies in this case is ExtensionSettings which is set in a OS/device specific way. To help diagnose this restriction, you can view your active polices in Chrome under chrome://policy/. In my case I had something like the following in my chrome://policy:
{
"*": {
...
"runtime_blocked_hosts": [ "*://*.google.com", ....]
},
I'm not aware of a generic workaround for this at the extension level. Instead I had to work with my company IT department to whitelist the extension.

Related

Chrome Extension not triggered on Google Calendar page (<all_url> in manifest.json)

I'm writing my first Chrome extension and it currently appears to work on all sites that I have tested apart from Google Calendar (which is really where I would like it!)
I've simplified the code as much as possible to try and fix this;
manifest.json:
{
"name": "TestExtension!",
"version": "0.0.1",
"manifest_version": 2,
"description": "Quick Test Extension",
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": ["content.js"]
}
]
}
content.js
console.log("Chrome extension go...");
Working
Not Working
Any ideas? What is different about Google Calendar. It works fine on Gmail and I have tried specifying the Calendar URL specifically as well with the same results.
Many Thanks to wOxxOm - A full Windows restart fixed the issue. (I really should have tried that, still not sure why killing all the Chrome processes didn't work but sorted now)

Why the extension with specific key declared can access chrome:// pages?

As we know, by default chrome extensions doesn't have access to chrome:// pages such as chrome://extensions and chrome://settings. ( Of course we can change chrome://flags/#extensions-on-chrome-urls flags however the following question is based on that we didn't change the default flags).
Recently I happen to find ChromeVox (offered by chrome.google.com) can work well in all pages including chrome:// pages. I checked the source code for this extension and find as long as we add the following line in manifest.json for any extension, the extension can work well in chrome:// pages.
"key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDEGBi/oD7Yl/Y16w3+gee/95/EUpRZ2U6c+8orV5ei+3CRsBsoXI/DPGBauZ3rWQ47aQnfoG00sXigFdJA2NhNK9OgmRA2evnsRRbjYm2BG1twpaLsgQPPus3PyczbDCvhFu8k24wzFyEtxLrfxAGBseBPb9QrCz7B4k2QgxD/CwIDAQAB"
So it looks like chrome has something like whitelist to allow specific extensions to break the default restrictions. Am I right? Is there official guide to clarify this behavior?
Appendix:
The following is a sample extension, you will find with the key, console will output test even in chrome://extensions pages; however once removing the key, nothing happens.
manifest.json:
{
"manifest_version": 2,
"name": "Test",
"version": "1.0",
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": [
"content.js"
]
}
],
"key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDEGBi/oD7Yl/Y16w3+gee/95/EUpRZ2U6c+8orV5ei+3CRsBsoXI/DPGBauZ3rWQ47aQnfoG00sXigFdJA2NhNK9OgmRA2evnsRRbjYm2BG1twpaLsgQPPus3PyczbDCvhFu8k24wzFyEtxLrfxAGBseBPb9QrCz7B4k2QgxD/CwIDAQAB"
}
content.js:
console.log('test');
"key" property in manifest.json uniquely defines the extension's ID in encrypted form.
Some Google extensions are unfairly(?) whitelisted by ID in the source code of chromium.
In this case, ChromeVox:
scripting_whitelist_.push_back(extension_misc::kChromeVoxExtensionId);
And then this whitelist is checked to see whether an extension can run everywhere in PermissionsData::CanExecuteScriptEverywhere, which is accessed in CheckRestrictedUrls where we can see restricted schemes: chrome://, chrome-extension://, chrome-debugger://

I can't activate a custom chrome content script extension outside of developer mode

I am having problem activating my own custom made script. It's working in the developer mode, when I load it as a directory. But when I pack it using the method provided by chrome it does not work.
It creates a .pem and .crx file, and when I drag and drop the extension inside the chrome://extensions page it shows. When pressing f5 it is deactivated every time, and when I check "also allow in incognito mode", that checkbox disappears immediately and doesn't come back.
Below my manifest file contents:
{
"manifest_version": 2,
"name": "Test script",
"version": "0.1",
"incognito": "split",
"content_scripts": [
{
"matches": [
"http://mail.google.com/*",
"https://mail.google.com/*",
"https://accounts.google.com/*"
],
"js": [
"jquery-2.1.4.min.js",
"content.js"
]
}
]
}
Any clue what's happening?
Chrome blocks extension installs on Windows unless they come from Chrome Web Store.
Install Chrome from a developer channel or use another OS.

Chrome extension doesn't work in Linux (works in windows)

Okay, this is weird.
This is my extension, and it works flawlessly in Windows (atleast on two win7 machines), but when I tested it on linux (CentOS6 and Fedora18) it failed to do anything when its icon was clicked (it should, at the very least, display an alert).
The options page still works, and saves data properly.
After enabling developer mode in chrome://extensions/ you can click _generated_background_page.html for the extension to see the JS console for the addon.
That's where I saw the following error:
Error during tabs.executeScript: Cannot access contents of url "https://www.google.com.au/". Extension manifest must request permission to access this host.
actual url in error is not relevant, does it to all sites
Thing is, the windows machines showed no such error, shouldn't this be platform independent?
The manifests are obviously the same, so how come the addon hasn't the required permissions only on linux machines?
Mac is untested, if someone could try that for me, it might be useful
FURTHER INFORMATION
The error message above was given with the following information;
Located in the function chromeHidden.handleResponse on line 22 of the script sendRequest
The "activeTab" permission was added in Chrome 26. Make sure that you've installed Chrome/Chromium 26+.
If you want to make your extension compatible with older browsers in the Chrome Web Store, add host permissions to the manifest file, plus the minimum_chrome_version key:
First upload an extension with the following manifest file:
{
"name": "Name of extension",
"version": "1.0",
"manifest_version": 2,
"permissions": [
"<all_urls>"
]
}
Then bump the version, change "<all_urls>" to "activeTab", add the "minimum_chrome_version" field and upload it again to the Chrome Web Store:
{
"name": "Name of extension",
"version": "1.0.1",
"manifest_version": 2,
"permissions": [
"activeTab"
],
"minimum_chrome_version": "26.0.0.0"
}

Error thrown when executing chrome.extension.getBackgroundPage()

I am working on my first extension and am trying to create a simple extension to inject a draggable div on a page. That works nicely, but I want to preserve the location of the div on the background page (I'm also trying out local storage, but want to understand why this isn't working).
I do not need a button so have not created a popup.html file, which, I believe, is entirely optional. It certainly has worked so far just injecting javascript files.
However, I now get the following error thrown when executing chrome.extension.getBackgroundPage():
Uncaught Error: chrome.extension.getBackgroundPage can only be used in extension processes. See the content scripts documentation for more details.
The content scripts documentation did not seem to identify anything wrong with my approach: http://code.google.com/chrome/extensions/content_scripts.html
Here is a redacted manifest I am using:
{
"name": "My helper",
"version": "1.0",
"description": "Tastes great",
"background_page": "background.html",
"content_scripts": [
{
"matches":["https://page.of.interest/*"],
"run_at":"document_idle",
"js":[ "jquery.js", "jquery-ui-1.8.17.custom.min.js", "my_content_script.js"],
"css": [ "my_content_script.css" ]
}
],
"permissions": [
"background"
]
}
So I am running this statement inside "my_content_script.js". Is this NOT considered part of the extension process? Can I only run this on a popup.html (or other possibly?) file?
If this is the case, then maybe it is easier to just use localstorage rather than trying to communicate through the dom with the extension process.
Hope I've been clear despite my ignorance about some of these concepts.
I don't think the docs explicitly say you can't use chrome.extension.getBackgroundPage() from a content_script but because the content_script has permissions more oriented with the page it is being run on it isn't allowed access. The docs do mention a few methods you can use however.
Unlike the other chrome.* APIs, parts of chrome.extension can be used by content scripts:
You will have to use message passing to communicate between the background_page and the content_script.
You have to use the chrome.cookies.get() in background.html, and then do the communication between your content script and background.html for exchanging cookie data.

Resources