json file like this:
"content_scripts": [ {
"css": [ "test.css" ],
"matches": [ "https://*/gallery/*" ]
}]
I want the user to be able to specify there own website into the manifest so it can be truly dynamic not just anything which matches "https://*/gallery/**"
Anyone know of any links to documentation or how to go about achieving this?
Related
I have a tiny chrome extension that works on google translate com
How can I make it working on all domain zones(not only .com)?
Tried the following but it doesn't seem to work.
"matches": [ "*://translate.google.*/*" ],
Error
Invalid value for 'content_scripts[0].matches[0]': Invalid host wildcard.
This is not a duplicate of Chrome extension: Run on all google domains and a specific page
I want it to work only on translate page.
"matches": [ "*://*/*" ],
"include_globs": [
"*://translate.google.*/*"
]
This part makes it working on google.com search page.
I don't need this.
Thanks to #wOxxOm
Go to http://www.google.com/supported_domains
Open console and paste the following:
copy(document.body.innerText.split(" ").map((item) => { return `*://translate${item}/*` }))
Go to your manifest file and replace matches": [] array with what you've just copied.
When running in test (reloading an unpacked extension), about 1 out of 5 times my event page's chrome.runtime object does not (yet) have the 'onInstalled' property.
// Cannot read property 'addListener' of undefined
chrome.runtime.onInstalled.addListener(...)
Feels like a race condition on startup within the extension container?
When the error throws, chrome.runtime only has the following:
{OnInstalledReason, OnRestartRequiredReason, PlatformArch,
PlatformNaclArch, PlatformOs, RequestUpdateCheckStatus, connect, sendMessage}
Try moving the event listener to a background script if they are in a content script. Content scripts have limited access to Chrome API. You can define it in the manifest. Then, if needed, you can send it from the background to a content script.
{
"manifest_version": 2,
"name": "someName",
"version": "0.0",
"description": ":D",
"content_scripts": [
{
"matches": ["https://*/*", "http://*/*"],
"js": ["content.js"]
}
],
"background":{
"scripts":["background.js"]
}
}
According to the linked Issue 601559, this was a bug in Chrome that was fixed in Chrome 51 (May 2016).
Working on a Youtube extension and will like to bring some of it into Facebook,
I'm able to modify the Youtube iframe inside Facebook posts, but the issue is that it's modify it in every site and not only on Facebook.
So I would like to know how can I set the specific parent window please?
I hope there is a way to set it simply in the manifest file,
otherwise I can just use JS to check for location.href as in Facebook it returns:
https://s-static.ak.facebook.com/common/referer_frame.php
Currently in my manifest file:
"content_scripts": [
{
"matches": [
"*://*.facebook.com/*",
"*://*.youtube.com/embed/*"
],
"css": ["styles/facebook.css"],
"all_frames": true
}
]
You can easily find the domain of the parent frame via location.ancestorOrigins, even across different domains. E.g, use the following manifest file:
"content_scripts": [{
"matches": [
"*://*.youtube.com/embed/*"
],
"js": ["js/facebook.js"],
"all_frames": true
}],
"web_accessible_resources": ["styles/facebook.css"],
and the following JS:
// Note: parentOrigin could be `undefined` in the top-level frame.
var parentOrigin = location.ancestorOrigins[0];
if (parentOrigin === 'https://facebook.com' ||
parentOrigin === 'http://facebook.com') {
var style = document.createElement('link');
style.rel = 'stylesheet';
// NOTE: This only works because the file is declared at the
// web_accessible_resources list in manifest.json
style.href = chrome.runtime.getURL('styles/facebook.css');
(document.head || document.documentElement).appendChild(style);
}
If the YouTube video is embedded via the Iframe API, you could also try to insert the style in the frame by matching the URL. E.g., without any JavaScript, the style can be loaded in the YouTube frame using:
"content_scripts": [{
"matches": [
"*://*.youtube.com/embed/*origin=https://facebook.com/*",
"*://*.youtube.com/embed/*origin=http://facebook.com/*"
],
"css": ["styles/facebook.css"],
"all_frames": true
}]
If you inject a content script both into the iframe and the parent frame, you can (using the background page as a message "router") ask the outer script.
Of use: content scripts can learn their place in the frame hierarchy.
So, the logic would be:
Youtube content script checks its hierarchy, obtaining its "index" on the tree, and computes the index of its parent.
CS messages the background with the index of its parent, requesting a check.
Background page gets the tab ID from the message, and messages all frames in the target tab with the request and parent index.
All content scripts that receive the message check their index. If it matches the parent frame, the content script checks its URL and reports back.
The background page routes the answer back to the original content script.
Tell me if you need help with any of those steps.
This has been bugging me and I can't figure out the solution.
"content_scripts": [
{
"matches": ["chrome-extension://_MSG_##extension_id/*"],
"js": ["contentscript.js"]
}
],
if i was to replace the "chrome-extensions://.." with a url such as http://google.com/* it will work.
I even tried fallowing the pattern on chrome develoeprs pag along with replacing extension id with the actual id.
I am basically trying to inject the content script into a local page "in the extension folder"
Sorry, but you aren't meant to be able to inject content scripts into other extensions. The docs are wrong, I have reported this issue while ago.
I'm trying to figure out how to exclude urls from content scripts injection.
The code for testing purposes is as follows:
"content_scripts": [
{
"exclude_globs": ["*"],
"js" : ["jquery.min.js", "markdown.js", "main.js"],
"css" : ["main.css"],
"matches": [ "file:///*.md", "file:///*.markdown", "*://*/*.md", "*://*/*.markdown"]
}
This seems to prevent javascript injection but stylesheets get injected anyways.
I've been reading about some exclude_globs and exlude_matches bugs so I'm starting to think that this in fact is some kind of bug.
Any kind of help will be appreciated.