I simpley want to get the extension fired if the action on 'onBeforeNavigate' happens. But for no reason the extension always trows this error:
Cannot read property 'onBeforeNavigate' of undefined
Error is on this line chrome.webNavigation.onBeforeNavigate.addListener(setProxy);
Here is my code so far:
popup.js
function setProxy(details){
console.log("Got fired!\n");
}
chrome.webNavigation.onBeforeNavigate.addListener(setProxy);
manifest.json
{
"manifest_version": 2,
"name": "Proxy Changer",
"description": "This extension Changes the Proxy settings every time you load a website",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png"
},
"permissions": [
"activeTab",
"webRequest",
"notifications",
"debugger",
"background",
"management",
"https://ajax.googleapis.com/",
"<all_urls>",
"webRequestBlocking"
],
"background": {
"scripts": ["popup.js"],
"persistent": true,
"js": ["jQuery.js", "popup.js"]
}
}
I hate to say that I am very new to the Google Chrome Extension API but for me the Extension API is not working... I don't know what I am doing wrong..
I already watched to videos but still same error...
I would appreciate your help. Thank you and kind regards!
just add "webNavigation" permission to Manifest.json
{
"name": "My extension",
...
"permissions": [
"webNavigation"
],
...
}
see documentation
https://developer.chrome.com/docs/extensions/reference/webNavigation/#event-onCreatedNavigationTarget
Related
Chrome Extension - Manifest V3
I am trying to build a simple chrome extension and am getting stuck on a particular error.
Uncaught (in promise) Error: Cannot access a "chrome://" URL
I found a way to counter the error, but it does not solve the problem itself.
I understood that when I use my extension, it works on "chrome://..." which I see when I inspect the extension, but can not figure out how to change that (if that even needs changing)
My code:
manifest.json
{
"version": "0.1.0",
"manifest_version": 3,
"name": "Super cool name",
"description" : "A super cool intro",
"author": "you wouldn't know him",
"permissions": ["storage", "activeTab", "scripting", "tabs"],
"host_permissions": ["tabs", "notifications", "http://*/*", "https://*/*"],
"background": {
"service_worker": "background.mjs",
"type": "module"
},
"action": {
"default_icon": {...},
"default_popup": "popup.html"
},
"icons": {...},
"content_scripts": [{
"matches": ["http://*/*", "https://*/*"],
"js": ["contentScripts.mjs"]
}]
}
background.mjs
chrome.tabs.onUpdated.addListener((tabId, tab) => {
if (tab.url?.startsWith("chrome://")) return undefined;
if (tab.active && changeInfo.status === "complete") {
chrome.scripting.executeScript({
target: {tabId: tabId},
files: ['contentScripts.mjs']
Any tips? Thank you for your time!
I am trying to import scripts and am apparently only able to get one. I am using this manifest:
{
"manifest_version": 3,
"name": "Auto_Select",
"description": "This extension auto selects Mturk HITs",
"version": "1.0",
"action": {
"default_icon": "auto_select.png",
"type": "module",
"default_popup": "auto_select.html"
},
"background": {
"service_worker": "worker_wrapper.js"
},
"permissions": [
"tabs",
"activeTab"
],
"host_permissions": [
"<all_urls>"
]
}
This is "worker_wrapper.js":
try {
importScripts("js.cookie.js", "auto_select.js", "cookie_mgmt.js");
} catch(e) {
console.log(e);
}
When I try to load the extension I get this error:
ReferenceError: document is not defined
at auto_select.js:26:1
at worker_wrapper.js:4:5
All the scripts are in the root directory for the extension so I don't understand why it doesn't error on the first script but rather on the 2nd. Can someone help me with this? TIA.
Hello i'm working on a google chrome extension and workaround with https://select2.github.io .
Here is my manifest:
{
"manifest_version": 2,
"name": "Extension Test",
"description": "Test extension",
"version": "1.0",
"content_scripts": [
{
"matches": ["https://www.mywebsite.com/*"],
"js": ["jquery-1.11.3.js", "content.js"]
}
],
"background": {
"scripts": ["jquery-1.11.3.js","background.js"]
},
"permissions": [
"activeTab",
"webNavigation",
"*://*/*"
]
}
Here is what i run directly into console:
$('#myselect2').select2('open');
Then the same code into content js is not working and firing the following error:
content.js:151 Uncaught TypeError: $(...).select2 is not a function
Is it possible to open select menu from extension to content of website and if so how ?
Try Replacing with
{
"manifest_version": 2,
"name": "Extension Test",
"description": "Test extension",
"version": "1.0",
"content_scripts": [
{
"matches": ["https://www.mywebsite.com/*"],
"js": ["jquery-1.11.3.js", "content.js"]
}
],
"background": {
"scripts": ["jquery-1.11.3.js","background.js"]
},
"permissions": [
"activeTab",
"webNavigation",
"*://*/*"
]
}
you are missing a '"' in the matches property.
It looks like you are not including the select2 plugin in your extension. Download it into your extension and, in your manifest, add:
"js": ["jquery-1.11.3.js", "select2.min.js", "content.js"]
EDIT
My chrome extension calling an api service in the background.js file and i can get the data. But after closing the browser window, i cant get the data from the api service in background.js file. It showing null value. When go to the chrome://extensions/ and reload the extension I can get the data.
When close the browser window, the data fetched is being reset and when open the browser, data not fetching. Data can be fetched from the api only after reloading the extension.
Why happening so. Does any one have an idea about this?
This is my manifest.json file
{
"manifest_version": 2,
"icons": {
"16": "images/icon16.png",
"32": "images/icon32.png",
"48": "images/icon48.png",
"128": "images/icon128.png"
},
"name": "Test",
"short_name": "Test",
"description": "Test",
"version": "3.0.0",
"background": {
"scripts": [
"build/background-bundle.js"
]
},
"browser_action": {
"default_popup": "popup.html"
},
"permissions": [
"tabs",
"cookies",
"storage",
"activeTab",
"http://*/",
"https://*/"
],
"content_scripts": [{
"matches": [
"<all_urls>"
],
"js": [
"build/content-bundle.js"
],
"run_at": "document_end"
}],
"options_ui": {
"page": "options.html",
"chrome_style": true
},
"content_security_policy": "script-src 'self' https://www.google-analytics.com/analytics.js https://api.algorithmia.com/v1/algo/algo://nlp/SummarizeURL/0.1.1; object-src 'self'"
}
You can't reload the background file based on anything other than reopening the browser or reloading the extension manually. What you should instead do is have a content script tell background.js to run getTaxonomyList again when the user log in happens.
background.js:
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.userLoggedIn) {
getTaxonomyList().done(function(list) {
sendResponse(list);
});
}
})
I have an extension that i'm trying to add content scrips alongside background scripts but it just says invalid when trying to temp load.
{
"description": "Creates tasks and calculates application incomplete date",
"manifest_version": 2,
"name": "Task Creator",
"version": "1.31",
"permissions": [
"http://*/*", "tabs", "https://*/*",
],
"icons": {
"48": "icons/page-48.png"
},
"web_accessible_resources": [
"style/popUpStyle.css",
"script/popUpTask.js",
"script/logicTaskFiller.js",
"js/autosize.js",
"style/jquery-ui.css",
"js/jquery-1.12.4.js",
"js/jquery-ui.js"
],
"content_scripts":{
"matches": ["*urlhere.com*"],
"js": ["comSendForm.js"]
},
"background": {
"scripts": ["background.js"]
},
"browser_action": {
"default_icon": "icons/page-32.png"
}
}
I'm not quite sure where i'm messing up. It works instantly after I take out the content scripts, but I'm doing multiple things with this extension and I really do need the content scripts to run on a certain page. Any help is appreciated.
error message
1477430058898 addons.webextension. ERROR Loading extension 'null': Reading manifest: Error processing content_scripts: Expected array instead of {"matches":["*://url.com/"],"js":["comSendForm.js"]}
The error that you are getting is that your manifest.json has the value of the content_scripts key as an Object. The value of the content_scripts key needs to be an Array of Objects, not just an Object.
In addition, you have the following problems:
The line:
"http://*/*", "tabs", "https://*/*",
should not have the trailing ,. This is actually reported as the first error, so you may have copied the contents of your manifest.json file inaccurately.
Your matches pattern is invalid. You probably wanted something like:
"matches": ["*://*.urlhere.com/"],
With all of those changes your manifest.json would look like:
{
"description": "Creates tasks and calculates application incomplete date",
"manifest_version": 2,
"name": "Task Creator",
"version": "1.31",
"permissions": [
"http://*/*", "tabs", "https://*/*"
],
"icons": {
"48": "icons/page-48.png"
},
"web_accessible_resources": [
"style/popUpStyle.css",
"script/popUpTask.js",
"script/logicTaskFiller.js",
"js/autosize.js",
"style/jquery-ui.css",
"js/jquery-1.12.4.js",
"js/jquery-ui.js"
],
"content_scripts": [
{
"matches": ["*://*.urlhere.com/"],
"js": ["comSendForm.js"]
}
],
"background": {
"scripts": ["background.js"]
},
"browser_action": {
"default_icon": "icons/page-32.png"
}
}