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.
Related
I am trying to check below point for my assignment programatically
1. check if turn on sync is enabled in chrome
EDIT:
So far i have developed a chrome extension and trying to get the chrome.storage.sync object
But i am unable to get the status of the turn on sync "whether synced or no"
Below is my manifest.json
{
"name": "Check Turn on sync",
"version": "1.0",
"description": "Build an Extension!",
"permissions": ["storage"],
"background": {
"scripts": ["background.js"],
"persistent": false
},
"manifest_version": 2
}
I have provided a background.js file
is there a way in chrome.storage.sync that provides status of the sync
I am going to answer my own question, as i was able to find the answer.
I was able to get the status of sync is turned on or no along with the email ids. Here is the code :
create a manifest.json file with below content
{
"name": "Test turn on sync",
"version": "1.0",
"description": "Extension",
"permissions":[
"identity",
"identity.email"
],
"background": {
"scripts": ["background.js"],
"persistent": false
},
"manifest_version": 2
}
Create a background.js file in the same folder
chrome.identity.getProfileUserInfo(function(data) {
if (data.id) {
alert(data);
}
else
{
alert("User has not turned on sync");
}
});
Add the folder as chrome extension Run the extension from chrome with the help of identity.email in permissions, you will be able to get even the email-id of the user who has turned on sync, along with status.
So I tried to create a new Chrome extension for the Chrome web store, and everything seemed to upload and publish correctly.
However now when I try to load the page for the extension, it is broken.
Chrome gives me this error in the console:
POST https://chrome.google.com/webstore/ajax/detail?hl=en-US&gl=US&pv=20170811&mce=atf%2Cpii%2Crtr%2Crlb%2Cgtc%2Chcn%2Csvp%2Cwtd%2Cnrp%2Chap%2Cnma%2Cc3d%2Cncr%2Cctm%2Cac%2Chot%2Ceuf%2Cmac%2Cfcf%2Crma%2Crae%2Cshr%2Cesl%2Cigb&id=gpgcbiaclhpaiknckdfdpbjkdgfkimmo&container=CHROME&_reqid=706656&rt=j 404 ()
And I get the error message:
There was a problem loading the item. Please refresh the page and try again.
As far as I can tell, my manifest.json is correct:
{
"name": "Chinese Personalized Colors",
"version": "0.0.0.1",
"short_name": "CPC",
"manifest_version": 2,
"description": "Color code individual Chinese characters",
"options_ui": {
"chrome_style": true,
"page": "options.html"
},
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*", "file:///*/*", "\u003Call_urls>"],
"css": ["mystyles.css"],
"js": ["jquery-1.7.2.min.js", "highlight_class_version.js", "content.js"],
"all_frames": true
}
],
"permissions": ["storage", "http://*/*"],
"background": {
"scripts": ["dict.js", "main.js", "background.js"]
},
"browser_action": {
"default_title": "CPC"
},
"icons": {
"128": "cpc-128px.png",
"48": "cpc-48px.png",
"16": "cpc-16px.png"
},
"author": "My Name",
"web_accessible_resources": ["css/*", "js/*", "images/*"]
}
All the images and all the files above exist in the zip uploaded to Google.
I tried logging out and logging back in as this was recommended advice by some people.
What could be wrong? Could it just be that the app hasn't been published for long enough to work correctly? The stack trace isn't really telling me much and I can't find any documentation on recent uploads causing an error like this anywhere.
It started working with no uploaded changes on my part. As far as I can tell, sometimes it takes time for an app to propagate to the Web Store, even when the listing appears.
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",.
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"});
});
The following code doesn't work for some reason:
Background.js
alert("1");
chrome.cookies.set({ url: "https://mywebsite.com", name: "SuperDuperTest" });
alert("2");
manifest.json
"permissions": [ "notifications", "https://mywebsite.com",
"cookies", "http://* /* ", "https://* / * " ],
Only alert("1"); ever fires. Alert 2 never does, why isn't my chrome cookies firing at all?
Where are looking to check whether your cookie is set or not?
Please use console.log() instead of alert()
Sample Code
manifest.json
Registered background page and given permissions for Cookies API.
{
"name": "Cookie API Demo",
"version": "1",
"description": "http://stackoverflow.com/questions/14448039/chrome-cookies-set-doesnt-even-run",
"permissions": [
"cookies",
"<all_urls>"
],
"background": {
"scripts": [
"background.js"
]
},
"manifest_version": 2
}
background.js
Trivial code to set cookie for cookies.html page
chrome.cookies.set({
"name": "Sample1",
"url": "http://developer.chrome.com/extensions/cookies.html",
"value": "Dummy Data"
}, function (cookie) {
console.log(JSON.stringify(cookie));
console.log(chrome.extension.lastError);
console.log(chrome.runtime.lastError);
});
Output
Go to https://developer.chrome.com/extensions/cookies.html and open developer tools as shown here, you can see cookie is being set!.
Click for Large Image
Further Debugging
If this sample code does not work, what are values of chrome.extension.lastError and chrome.runtime.lastError?
Make sure you declared the cookies permission.
To use the cookies API, you must declare the "cookies" permission in
your manifest, along with host permissions for any hosts whose cookies
you want to access. For example:
{
"name": "My extension",
...
"permissions": [
"cookies",
"*://*.google.com"
],
...
}
source: developer.chrome.com