I am still new to Chrome extension development, and I am currently playing a bit with it. I have now come across an error that I cannot explain. My guess is that some permission is missing. But according to the API specs, I have set all the necessary permissions. My test extension should change the value of chrome.contentSettings['javascript'].set
. Actually, I want to disable JavaScript via this extension.
manifest.json
{
"manifest_version": 3,
"name": "Block JavaScript",
"description": "BlockJavascript",
"version": "0.0.1",
"icons": {
"16": "images/shield_green.png",
"48": "images/shield_green.png",
"128": "images/shield_green.png"
},
"action": {
"default_icon": {
"16": "images/shield_green.png",
"24": "images/shield_green.png",
"32": "images/shield_green.png"
},
"default_popup": "popup.html",
"default_title": "Block JavaScript"
},
"permissions": ["tabs", "contentSettings"],
"options_page": "options.html",
"background": {
"service_worker": "background.js"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"all_frames": true,
"run_at": "document_start",
"js": ["inject.js"]
}
]
}
inject.js
chrome.contentSettings['javascript'].set({
primaryPattern: '<all_urls>',
setting: 'block'
});
Chrome Browser Error Log
Uncaught TypeError: Cannot read properties of undefined (reading 'javascript')
Stack Trace inject.js:1 (anonymous function)
chrome.contentSettings['javascript'].set({ //Error in this line
primaryPattern: '<all_urls>',
setting: 'block',
});
I hope that someone can help me and explain to me why this is happening. If you have any useful learning materials (besides the Chrome dev docs), I would be pleased if you could provide me with some. I generally find it very difficult to find learning material/videos explicitly for Chrome extension (manifest v3) development.