Do I need to reference the auth.js in my manifest for this code to work?
I am building a Google Chrome Extension that will provide a YouTube video in a popup after querying YouTube. To do this with javascript, I am told that I must first set up an auth.js.
I built the auth.js just as mentioned here. I made sure to get a project id from the Developer Console.
Here is my manifest.json
{
"manifest_version": 2,
"name": "myOverlay",
"description": "This extension will create a popout that links to a video specific to the current webpage",
"version": "1.0",
"permissions": [
"tabs",
"https://*.youtube.com/",
"https://*.ytimg.com/"
],
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"content_security_policy":
"script-src 'self' https://*.youtube.com https://*.ytimg.com; object-src 'self'"
}
No, just reference auth.js from popup.html like normal.
Any files within the extension directory are found automatically, you don't need to tell the manifest about them.
Related
I'm going to make a program that inserts HTML code into a specific tag on a web page through Chrome Extension MV3.
I would like to use jquery to do the above work. However, I searched on Google and found that it did not show how to do it in the Manifest V3 environment.
How do I get jquery from Chrome Extension Manifest V3?
//manifest.json
{
"name": "test",
"description": "Build an Extension!",
"version": "1.0",
"manifest_version": 3,
"background": {
"service_worker": "background.js"
},
"permissions": ["storage", "activeTab", "scripting", "activeTab","tabs"],
"action": {
"default_popup": "popup.html"
}
}
recently I came across an error during trying to get JQuery to my chrome extension. I wrote following code and then when I try to reload my extension in Chrome browser I get the message:
Failed to load extension
Error
Could not load javascript 'jquery.js' for content script.
Could not load manifest.
The file of jquery was downloaded from their webpage (compressed production 3.5.1).
I checked several webpages connected to this problem but I couldn't find the solution.
Files in which inserting JQuery matters are below:
manifest.json
https://ideone.com/EGKlfQ
"manifest_version": 2,
"name" : "name",
"version": "1.0",
"offline_enabled": true,
"content_scripts": [
{
"matches": [
"https://www.zalando-lounge.pl/*"
],
"js": ["jquery.js","content.js"]
}
],
"background" : {
"scripts": ["background.js"]
},
"browser_action":{
"default_icon": "img/icon.png",
"default_popup": "popup.html",
"default_title": "A popup will come here"
},
"permissions": ["tabs","storage"],
"content_security_policy": "script-src 'self' https://cdnjs.cloudflare.com/; object-src 'self'"
popup.html
https://ideone.com/exMgYq
<script type="text/javascript" src="jquery.js"></script>
...other code in this file doesn't matter in this case...
I made a web app in React which i wanted to use as a chrome extension. But when I load the build folder and click on the icon I get a small white box and nothing else
Can someone please tell me what I did wrong.This is my manifest.json
{
"manifest_version": 2,
"name": "name",
"description": "desc",
"version": "0.0.1",
"browser_action": {
"default_popup": "index.html",
"default_title": "Open App"
},
"content_security_policy": "script-src 'self' 'sha256-OJ+UtHOO3C5swdxKPX5j37pdN56CatocDV87+5UMu9Q='; object-src 'self'", "permissions": [
]
}
I am developing a chrome extension using react which has a background script and multiple browser action js files. This is my project structure
MyExtension
|__build
|__public
| |__images
| |__scripts
| |__index.html
| |__manifest.json
|
|__src
|
|___browser action js files...
And this is my manifest.json
{
"name": "MyExtension",
"version": "0.0.1",
"manifest_version": 2,
"description": "MyExtension",
"icons": {
"16": "images/icon-16.png",
"128": "images/icon-128.png"
},
"default_locale": "en",
"background": {
"scripts": [
"scripts/background.js"
],
"persistent": false
},
"permissions": [
"background",
"notifications",
"tabs",
"storage",
"alarms",
"webNavigation",
"*://*/"
],
"browser_action": {
"default_icon": {
"16": "images/icon-16.png",
"19": "images/icon-19.png",
"38": "images/icon-38.png",
"128": "images/icon-128.png"
},
"default_title": "MyExtension",
"default_popup": "index.html"
},
"web_accessible_resources": [
"images/icon-48.png"
],
"content_security_policy": "script-src 'self' 'sha256-
5As4+3YpY62+l38PsxCEkjB1R4YtyktBtRScTJ3fyLU='; object-src 'self'"
}
I use the command npm run build for building the project where build is set to react-scripts build. Earlier, I used to debug the browser action files by inspecting the extension popup and setting breakpoints in js files under the src directory in the Source directory of the chrome developer tools window. I used to debug the background script by clicking on the background page link in the chrome://extensions page which is shown in the image below.
But recently, I notice that the browser action source files are not present under the 'Sources' tab as shown in the image below.
I just get two chunk.js files which seem to be the bundled version of all my files in the src directory. They have a lot of auto-generated code and hence I am not able to set breakpoints in the files I want.
Is there any way for me to get the individual source files to appear in the Sources tab of the Developer Tools Window?
I want to use AngularJS in a Chrome extension but I have an error like this:
Error: SECURITY_ERR: DOM Exception 18
Error: An attempt was made to break through the security policy of the user agent.
at new listConnection
manifest.json :
{
"name": "Chrome auditor connection",
"version": "1",
"icons": { "48": "icone.png",
"128": "icone.png" },
"description": "Chrome-auditor-connection is an extension for Google Chrome browser. It ensures that nobody connects to your browser with your profile.",
"background": {
"scripts": [
"chrome_ex_oauthsimple.js",
"chrome_ex_oauth.js",
"background.js"
]
},
"browser_action": {
"default_title": "Chrome auditor connection",
"default_icon": "icone.png",
"default_popup": "index.html"
},
"permissions": [
"storage"
],
"web_accessible_resources": ["index.html"],
"sandbox": {
"pages": ["index.html","index.js","angular.min.js"]
},
"manifest_version": 2
}
index.js :
function listConnection( $scope) {
$scope.connections = JSON.parse(localStorage['connectionHistory']);
}
I think the JSON.parse() is blocked by the Chrome "Content Security Policy" (CSP).
Do you have any solution?
Your index.js is sandboxed as defined in your manifest.json file.
"A sandboxed page will not have access to extension or app APIs"
So it can't access localstorage.
Remove the sandbox or use something like https://github.com/jamesmortensen/chrome-sandbox-storageAPI for sandboxed pages.
There are two answers for you:
Add ng-csp to your <html> tag, like this <html ng-csp ng-app="AngularAppName"> . See this SO answer
Add this line to manifest.json file
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self' "
Problems in your code
These are some of problems i see so far with code shared!.
Your index.html is being used as default_popup, web_accessible_resources and in sandbox Pages . It is functionally incorrect, what is you want to develop?
Why do you want to put angular.min.js in sandbox location?
Is index.js used by index.html, if so there is no need to list it explicitly.
Storage is an object per domain, your localstorage differs from sandbox and other pages.