Chrome extension content script is not injecting in to most pages - google-chrome

I'm trying to build a basic extension that injects an alert script in to every page loaded. But it seems that the script is injecting only to some pages (most pages it's not injected in to), and I couldn't find a pattern in how it picks the pages to get injected to.
This is the manifest:
{
"name": "TestingTest",
"version": "0.1.1",
"description": "Testing Tests!",
"manifest_version": 2,
"content_scripts": [
{
"matches": ["http://*/", "https://*/"],
"js": ["content.js"],
"run_at": "document_end"
}
],
"background": {
"page": "background.html"
},
"permissions": [
"tabs",
"http://*/", "https://*/",
"cookies"
],
"icons": {
"16": "my_icon_64.png",
"32": "my_icon_64.png",
"48": "my_icon_64.png",
"128": "my_icon_64.png"
}
}
and this is ccontent.js:
alert("content script");
console.log("content script")
I'm getting the alert only on a select few pages. The pages that it's injected in to seem to vary if I load the extension in different Chrome profiles.

Your content script is probably loading only on pages where the pathname is just /. Add an extra * at the end of your url patterns:
"matches": ["http://*/*", "https://*/*"]

Related

Error processing manifest in firefox

I have developed a extension primarily focused on chrome which works but now i need that extension to work in firefox either so I checked by loading the extension by going to about:debugging page and loading temporary addons. Currently, I go an error. I got error something like this
Reading manifest: Error processing options_page: An unexpected
property was found in the WebExtension manifest.
Reading manifest: Error processing oauth2: An unexpected property
was found in the WebExtension manifest.
Reading manifest: Error processing key: An unexpected property was
found in the WebExtension manifest.
Here is what my manifest file looks like(I removed options_page)
manifest.json
{
"version": "1.0",
"name": "Browser Extension",
"manifest_version": 2,
"description":
"This extension allow the user to select the text and redirect to the application",
"page_action": {
"default_title": "Select Text",
"default_popup": "index.html"
},
"icons": {
"16": "img/browser16.png",
"48": "img/browser48.png",
"128": "img/browser128.png"
},
"background": {
"scripts": ["extension/js/background.js"],
"persistent": true
},
"content_scripts": [
{
"matches": [
"https://mail.google.com/mail/*/*",
"http://mail.google.com/mail/*/*"
],
"js": ["extension/js/jquery.min.js", "extension/js/content.js"],
"css": ["extension/css/main.css"],
"run_at": "document_end"
}
],
"permissions": [
"contextMenus",
"tabs",
"storage",
"webNavigation",
"notifications",
"cookies",
"identity",
"*://mail.google.com/mail/*/*",
"https://www.googleapis.com/*",
"https://*.googleusercontent.com/*"
],
"web_accessible_resources": ["img/browser128.png", "img/ios-link.svg"],
"oauth2": {
"client_id":
"114446495690-8ejpdgvmn8vc9pblteupetas.apps.googleusercontent.com",
"scopes": ["profile", "https://www.googleapis.com/auth/gmail.readonly"]
},
"key":
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnqFjzbt+LtejD1JhOyMUbejOHdLoemzryr+ZQHK2CEKuI0yVVYToFs7eNusH/hfxhnyF27G4BU8apsTc695EpVQGD0ANKdt6BjubRnA/4VcdkmfdD3D9nsdCc+fHkINRU5e05grfs/BETWW/JAUULduaNWGfhT7"
}
How do i resolve above issues to make it firefox compatible as well?

content script not being injected into extension html page

I have an extension that gets JSON data from a site for a list of characters and their resources when chosen from a menu. I'm using a single html page and trying to update it with javscript to modify the code for the menu. The only thing is that I can't get the content script injected/loaded into the html page.
When my extension is run, the path for the rem.htm file is shown as 'moz-extension://a02e52b1-e41d-4d28-844b-a8466a1dd67b/rem.htm' which gives an invalid error for the 'matches' key in the console.
What else can I use?
manifest.json:
{
"description": "Resource Manager for Path of Exile",
"manifest_version": 2,
"name": "Path of Exile Resource Manager",
"version": "1.0",
"content_scripts":
[
{
"matches": ["file:///rem.htm"],
"js": ["modify-page.js"]
}
],
"background":
{
"scripts": ["background.js"]
},
"browser_action":
{
"default_icon":
{
"16": "icons/rem_16.png",
"32": "icons/rem_32.png",
"64": "icons/rem_64.png"
}
},
"permissions":
[
"*://www.pathofexile.com/",
"webRequest",
"tabs",
"activeTab"
]
}
I figured it out. I didn't realize I had modify-page in a separate directory. I was then able to add '' to matches and it finally worked!

Chrome extension to work on all the sites and perform different action just for few sites

I'm trying to make an extension to work on all the site.And also for some site specific sites(Google and LinkedIn) I want some others action to be performed. I have managed to work it on Google search google.com/search and LinkedIn search pages linkedin.com/vsearch/ and perform action A and B respectively. But i'm stuggling to make it work on all others sites to perform action C.
{
"manifest_version": 2,
"name": "extname",
"description": "Welcome to my ext",
"icons": {
"48": "images/ext.png"
},
"version": "2.6",
"background": {
"scripts": [ "js/jquery-2.1.4.min.js", "js/background.js","js/select2.min.js","js/lodash.js","js/bootstrap.min.js","js/bootstrap-select.min.js" ]
},
"content_scripts": [{
"css": [ "css/select2.css" ,"css/bootstrap.min.css","css/bootstrap-select.min.css" ],
"js": [ "js/jquery-2.1.4.min.js", "js/extension_google_result.js" ,"js/select2.min.js" ,"js/bootstrap.min.js","js/bootstrap-select.min.js"],
"matches": [ "*://*.google.com/search*" ] //for Google Search page
},
{
"css": [ "css/extension_linkedin_search_page.css", "css/bootstrap.min.css","css/bootstrap-select.min.css" ],
"js": [ "js/jquery-2.1.4.min.js","js/select2.min.js" ,"js/bootstrap.min.js","js/bootstrap-select.min.js"],
"matches": [ "*://*.linkedin.com/vsearch/*"] //for Linkedin Search page
},
{
"css": [ "css/extension_linkedin_search_page.css" ,"css/bootstrap.min.css","css/bootstrap-select.min.css","css/select2.css" ],
"js": ["js/lodash.js", "js/jquery-2.1.4.min.js", "js/extension_linkedin_sales_navigator_search_page.js" ,"js/select2.min.js" ,"js/bootstrap.min.js","js/bootstrap-select.min.js", "js/akash.js"],
"matches": [ "<all_urls>"] //for all other sites
}
],
"content_security_policy": "script-src 'self' 'unsafe-eval' https://d37gvrvc0wt4s1.cloudfront.net https://*.pusher.com; object-src 'self'",
"browser_action": {
"default_icon": "images/found128.png",
"default_popup": "html/extension-login-popup.html",
"default_title": "Search with Found"
},
"permissions": ["cookies","tabs", "http://*/*", "https://*/*","contextMenus", "tabs", "storage", "\u003Call_urls>", "notifications", "webRequest" ]
}
But here the first two cases for google and linked in search works perfectly and i'm getting callbacks(Action A and B) on only those pages as expected.I'm also able to call action c on other sites.But actin c is also been calling on google and linkedIn search pages also on every new tab action which i don't want.How can i fix that? Any idea?
Take a look at Content Scripts, you will find you can use exclude_matches in your manifest.json to exclude pages that your content script would not be injected into.

Matching content script with last keyword match

I have a page in block.html in extension directory. I want match content script with the page name.
Check my manifest file below, there is content_script match:
{
"manifest_version": 2,
"name": "Cobra Security ATD",
"version": "1.0",
"description": "Cobra Security Advance Threat Defence.",
"icons": {
"48": "img/48-48.png",
"128": "img/128-128.png"
},
"browser_action": {
"default_icon": "img/16-16.png",
"default_title": "Cobra Security Advance Threat Defence",
"default_popup": "popup.html"
},
"background": {
"scripts": ["js/jquery-1.11.1.js","js/event.js"],
"persistent": false
},
"content_scripts": [
{
"matches": ["http://*/*block.html"],
"js": ["js/jquery-1.11.1.js","js/block.js"]
}
],
"permissions": [
"<all_urls>",
"tabs",
"webNavigation"
]
}
One does not inject content scripts into chrome-extension:// pages. You cannot indicate this schema in the manifest, and you can't indicate a host permission that would allow you to inject it.
Since it's an extension that you control, you don't need to inject scripts for anything!
If you want to put code in it, you.. put code in it, in a <script
src="..."> fashion.
If you want to inform the page of some event, you use Messaging.
If you want to pass some information when you open the page, you can
use this trick, sending a request back for data.

Chrome Extension Notification Exception: DOM Exception 18

I'm creating a chrome extension but I'm having some difficulties in use notifications webkit. When I try to display a notification, an exception is thrown:
Uncaught Error: SecurityError: DOM Exception 18
Bellow follow my Javascript code:
var icon = 'icon_48.png';
var title = 'Test Plugin';
var body = message;
var popup = window.webkitNotifications.createNotification(icon, title, body);
popup.show();
Bellow follow my manifest.json:
{
"name": "Test Plugin",
"version": "1.0.6",
"manifest_version": 2,
"description": "This is a test",
"browser_action": {
"default_icon": "images/icon_32.png",
"default_popup": "popup.html"
},
"icons": {
"128": "images/icon_128.png",
"16": "images/icon_32.png",
"48": "images/icon_48.png"
},
"permissions": [
"http://*/*",
"https://*/*",
"contextMenus",
"tabs",
"notifications",
"management",
"webRequest"
],
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["webtoolkit-sha1.js","content.js"],
"run_at": "document_end",
"css" : ["css/style.css"]
}
],
"web_accessible_resources": ["webtoolkit-sha1.js","inject.js","icon_48.png"]
}
What am I doing wrong?
Thanks everybody!
Information Update:
manifest.json has the attribute notifications in permissions section but when I print the webkitNotifications.checkPermission() the result was 1 (PERMISSION_NOT_ALLOWED).
The notifications permission only applies to the extension's process. In order to get your code to work, a background (or event) page needs to be added, which creates the notification. The content script can use the messaging API to request the notification.