I have created a chrome extension which is connected to Native messaging application. Native messaging app needs to know if the extension is unchecked or unloaded. Is there any event by which i can catch that the extension is uninstalled or unchecked? So that i can send message to my native messaging app to notify
This can simply be detected if reading from STDIN when listening for messages from the browser in the native messaging host fails (e.g. fread returns not the buffer length passed in). Google Chrome disconnects STDIN when it unloads the extension.
Related
I have published a native messaging add-on on Mozilla, but the native messaging host (native app) runs only once, if I restart firefox, the native app does not start.
Here is the scenario:
Step 1: I install the native app on Windows 10 using the setup file, the setup also configures the registry key under
HKEY_CURRENT_USER\Software\Mozilla\NativeMessagingHosts
HKEY_LOCAL_MACHINE\Software\Mozilla\NativeMessagingHosts\
Step 2: Start firefox, download and install the public released (signed) add-on from mozilla. The add-on icon shows on Firefox, I click the icon, the add-on popup page shows, click the menu items on the popup, the add-on works as expected, the native app works too, it receives messages from add-on, and sends messages back to the add-on.
All is OK, it seems the native messaging add-on works well. However, after I restart firefox, click the add-on icon, click the menu items on the popup menu, nothing happens. I type about:debugging, in the console window, there is error message "Unchecked lastError value: Error: port is null".
This error only happens while using the signed add-on, using local version un-signed addon, the native messaging host and add-on always run, no such problem.
I want to know, when download and install the addon from Mozilla, except the addon's XPI file, are there other files also downloaded? Maybe these other files run after firefox restarts, and these files or their configuration prevent the native app from running.
Here is the code snippet in background page:
function connectToNativeHost()
{
var nativeHostName = “com.some-company.test”;
port = chrome.runtime.connectNative(nativeHostName);
console.log(port)
port.onMessage.addListener(onNativeMessage);
port.onDisconnect.addListener(onDisconnected);
}
function onDisconnected()
{
console.log(chrome.runtime.lastError);
console.log(‘disconnected from native app.’);
port = null;
}
I test again and again, I find that after firefox restarts, the native app never runs again, firefox does not create a process for the native app.
Thank you for your help!
I published my extension on following link https://chrome.google.com/webstore/detail/poenibgdeeoelggbbbhdddojjjglhdjm/publish-accepted?authuser=0&hl=en.
When the extension runs the nativemessaging host and native messaging host sends a message it shows following error This extension may have been corrupted., and stops working.
The extension works fine in developer mode.
This extension may have been corrupted.
This is a message that Chrome shows if any of the files inside the extension folder change. When an extension is published, Web Store adds a Google-signed list of file hashes to the extension (in the _metadata folder), and any detected change is interpreted as a hijack attempt and leads to the extension being disabled.
You don't run into this in development mode, because Chrome does not consider file changes as abnormal (it is, after all, in active development).
If this is what your native component does (e.g. adds files to the extension or changes them), you can't use this technique. In particular, this does not allow you to change the extension's code externally.
Use other methods of storage of variable information in an extension, e.g. the storage API or IndexedDB, and other methods of communication, e.g. the native host communication protocol or a local webserver in the native component (but think about security if you're doing that).
There is a way to enable/disable google chrome extension with a command line ?
I would like enabled un extension already installed by terminal.
Launch Chrome with extension parameter may help you.
Example:
launch chrome with cmd
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -no-first-run --load-extension="extension path"
Here's an architecture example for what wOxxOm proposed in comments:
An extension can enable/disable other extensions with chrome.management API and "management" permission.
An extension can spawn a companion daemon process that communicates with the rest of OS using Native Messaging's chrome.runtime.connectNative().
Said daemon can create a named pipe that you can write to from the command line, and pass whatever commands are sent to the pipe to the extension using the Native Messaging protocol.
Note that Chrome cannot be contacted from "outside" directly: it must spawn a process on its own, and then you can communicate with the process.
Alternatively (if you don't want to use the Native Messaging protocol, or want the daemon to exist independent of Chrome), your daemon can open a local WebSockets server and your extension can communicate through that. However, it would be possible to impersonate your extension in that case.
I created a "packaged app" for Chrome browser and I do not want others to debug the app.
Is there a flag in the manifest or any other way to prevent debugging?
If you use native client and don't use any HTML/JS/DOM, except for loading the native client module, then you would not be able to debug very much with devtools.
I am developing a chrome packaged app. As part of the app i need to know, when user uninstalled the app. I could not find any method as part of the API,to read such a event when it happens. In extensions we have chrome.management api to do this, but chrome packaged app doesn't have this permission. Any help would be highly appreciated.
Try using chrome.runtime.setUninstallURL, this allows you to set a URL which is loaded as soon as the App is removed from Chrome. It does not require any additional permissions.