trying to create chrome extension but manifest.json not working [duplicate] - javascript

This question already has answers here:
How to migrate manifest version 2 to v3 for chrome extension?
(2 answers)
How to open the correct devtools console to see output from an extension script?
(3 answers)
Closed 17 days ago.
so basically, I have build a small game using javascript and trying to create a chrome extension. This is my first time not sure what I am doing wrong in the manifest.json.
I have got multiple folder, 3 folders for images. Not sure what is wrong here.
{
"manifest_version": 3,
"name": "DICE CAR RACE",
"version": "1.0",
"description": "CLICK THE DICE AND MOVE THE CAR",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "index.html"
},
"permissions": [
"activeTab"
],
"web_accessible_resources": [{
"resources" : ["diceImg/dice1.jpeg",
"diceImg/dice2.jpeg",
"diceImg/dice3.jpeg",
"diceImg/dice4.jpeg",
"diceImg/dice5.jpeg",
"diceImg/dice6.jpeg",
"cars/car1.jpeg",
"cars/car2.jpeg",
"cars/car3.jpeg",
"cars/car4.jpeg",
"cars/car5.jpeg",
"cars/car6.jpeg",
"racecourse/racetrack.jpeg"],
"matches": ["<all_urls>"]}
]
}

Related

Chrome extension - Detect URL and execute an application

I know that with a basic chrome extension we can select domains where our extension will work (<all_urls>), but is this possible to execute an application ( internal ) when the user visit a specific domain?
I looked previously and saw "Native Messaging". ( I'm currently studying arithmetics ) I want my extension to open automaticly calc.exe when I'm on my working lab's website.
I already did this:
manifest.json
{
"name": "Mon extension",
"version": "0.0.1",
"background": {
"scripts": [ "background.js" ]
},
"browser_action": {
"default_title": "Ouvrir la calculatrice"
},
"permissions": [
"nativeMessaging"
],
"manifest_version": 2
}
But I did not understand how to manage the javascript part, can someone explain it to me ?
My calc.bat's manifest.json :
{
"name": "application",
"description": "Lauching my app",
"path": "C:\\Users\\root\\Documents\\calc.bat",
"type": "stdio",
"allowed_origins": [
"chrome-extension://blfgmcilkaooeokpomhcpnfnhppjklcb"
]
}
Calc.bat is simply: #echo off & start calc.exe
Thanks in advance. If my question is not clear enough, tell me, I'll modify it.
CouldnĀ“t get yours to work but the example I linked worked perfectly so started editing that one and ended up with this :
Download sample host
Edit native-messaging-example-host.bat and replace with :
#echo off
calc.exe
Run install_host.bat
Make a folder called app on same directory as host folder
Create 3 files : background.js, main.js, manifest.json
The content is:
background.js:
chrome.runtime.onMessage.addListener(function(message,sender,sendResponse){
if (message.action == "open app") {
chrome.runtime.connectNative("com.google.chrome.example.echo");
}
});
main.js:
chrome.runtime.sendMessage({action: "open app"}, function(response) {
console.log(response);
});
manifest.json:
{
// Extension ID: knldjmfmopnpolahpmmgbagdohdnhkik
"key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDcBHwzDvyBQ6bDppkIs9MP4ksKqCMyXQ/A52JivHZKh4YO/9vJsT3oaYhSpDCE9RPocOEQvwsHsFReW2nUEc6OLLyoCFFxIb7KkLGsmfakkut/fFdNJYh0xOTbSN8YvLWcqph09XAY2Y/f0AL7vfO1cuCqtkMt8hFrBGWxDdf9CQIDAQAB",
"name": "Native Messaging Example",
"version": "1.0",
"manifest_version": 2,
"description": "Send a message to a native application.",
"content_scripts": [{
"js": ["main.js"],
"matches": ["<all_urls>"]
}],
"background": {
"scripts": ["background.js"]
},
"permissions": [
"nativeMessaging"
]
}
Finally, install the extension. This one in particular will open calc.exe every time you open/load a page, which can be easily changed with matches.
Another thing to note is that without the key in the manifest, it does not seem to work.

Why webextension installation failure?

I am learning how to write webextensions.
so I'm copying "beastify" extension from here from scratch.
But my copied version's installation failure.
I don't know why installation is failure.
There are same directory structure, same meaning code, same picture file.
I suppose there are causes of installation failure in manifest.json.
my manifest.json:
{
"manifest_version": 2,
"name": "Beastify",
"version": 1.0,
"description": "add a browser action icon to the toolbar. Click the button to choose a beast. The active tab's body content is then replaced with a picture of the choosen beast.",
"icons": {
"48": "icons/beasts-48.png"
},
"permissions": [
"activeTab"
],
"browser_action": {
"default_icon": "icons/beasts-32.png",
"default_title": "Beastify",
"default_popup": "popup/choose_beast.html"
},
"web_accessible_resources": [
"beasts/frog.jpg",
"beasts/turtle.jpg",
"beasts/snake.jpg"
]
}
The value of version must be string.
Please replace "version": 1.0, to "version": "1.0",.

Can't access window object from within chrome extention [duplicate]

This question already has answers here:
Chrome extension - retrieving global variable from webpage
(5 answers)
Access window variable from Content Script [duplicate]
(1 answer)
Closed 7 years ago.
I'm developing a chrome extension that will do something if it detects a specific object on the window object. For example in content.js I have
var el = document.getElementsByTagName("html");
console.log(el[0].ownerDocument.defaultView.someObj);
This logs undefined. If I run the same code within the browser console. I will see that someObj exist. I get the correct element with
var el = document.getElementsByTagName("html");
but it doesn't seem like I can get the correct window object. Any ideas?
my manifest looks like
{
"manifest_version": 2,
"name": "My Ext",
"version": "0.1",
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": ["content.js"]
}
],
"browser_action": {
"default_icon": "images/logo.svg"
}
}

Chrome extension inject js

I want to create a new chrome extension but it don't work.
I want to inject a js file into web page (all web page,not only one.If i push the chrome icon on google the script must execute,if i push the icon on facebook it must execute ect.)
this is background.js
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript({
null,{file: "backgrounds.js"} });
});
this is backgrounds.js
document.body.innerHTML="display div elem with style and id";
this is manifest.json
{
"name": "MyExt",
"description": "an extension,what else?",
"version": "1.0",
"permissions": [
"activeTab"
],
"content_scripts": [
{
"matches": ["http://*/*"],
"js": ["background.js"]
}
],
"browser_action": {
"default_title": "myExt"
},
"manifest_version": 2
}
what i wrong?
I'm on windows 8.1 Update 1 with chrome last version
Your manifest is wrong: you should set background.js as your background script:
"background" : { "scripts" : [ "background.js" ] },
and remove the "content_scripts" section.
The "activeTab" permission means that you don't need to specify host permissions to inject in the current tab upon browser action click, so no other permissions are needed.
The tabId argument is optional, you can just drop it instead of passing null. And your invocation is wrong (you're wrapping two arguments in a single object). Here's the correct way:
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript({file: "backgrounds.js"});
});

How to debug Google Chrome background script? [duplicate]

This question already has answers here:
Accessing console and devtools of extension's background.js
(9 answers)
Closed 7 years ago.
I have very simple extension:
manifest.json
{
"name": "historyCleaner",
"version": "0.1.1",
"manifest_version": 1,
"description": "This is my first Chrome extension",
"background": {
"scripts": ["cleaner.js"]
},
"permissions": [
"history"
]
}
cleaner.js
chrome.history.onVisited.addListener(function(HistoryItem result) {
console.log("it works!");
alert("it works!");
});
I've loaded it in Google Chrome, it is turned on and... it doesn't work. It doesn't log anything in console, it doesn't alert anything and what is worse, I can't find it in developers tools "Scripts" tab. How can I find why it doesn't work?
//edit
I've changed manifest.json to this one:
{
"name": "historyCleaner",
"version": "0.1.5",
"manifest_version": 1,
"description": "This is my first Chrome extension",
"background_page": "background.html",
"permissions": [
"history",
"background"
]
}
And embeded JavaScript in background.html
and also if your console.log("it works!"); does not show up, then that's mean chrome.history.onVisited is not fired yet.
ps: For function(HistoryItem result), you may want to change it to function(result).
This response might be late but would help the rest. if your background.html has javascript errors then the page will not load (to inspect).
To find out whats wrong with your background.html, under chrome://chrome/extensions/ (i.e., manage extensions), click on the background.html link. This will load the developer tools but without background.html. At the botton-right of the window, you will see a red error symbol, and clicking on it will provide line numbers that needs to be fixed.

Categories

Resources