I am trying to get Native Messaging between my chrome extension and my c# application. But below are my questions :
How to open only one Native app at a time ?. Clicking on the extension again will open the Native app again & again.
Can I communicate with an already open native app?
I built my extension and native app using the code in the following question.
Native Messaging Chrome
Native Messaging works by starting a new application process, then communicating with it over STDIO as long as Chrome keeps the connection open. If you don't keep the connection open, you can't "reconnect" to an application. To keep the connection open, you'll probably need to open it from the event script.
See this question: How to get Chrome Native Messaging to Listen to application? It discusses some of this topic, including C#-specific ways to keep it a single instance.
Furthermore, consider using alternative solutions, such as web communication (for example, WebSockets) to a local port exposed by your native code, though it creates new security questions (how to make sure it's your extension talking to it?).
Related
Google oAuth is not supported in android webView. Google recommends to use chrome custom tab for proceeding oAuth. I have also requirements of js call from my web app to native. How to configure to call native methods from web app using chrome custom tab in android similarly like js interface in webView?
Update 1
This mod Chang marked the post as duplicate but the post is different. I don't want to run any JS in my web app from native. I want to invoke method from web app to my native code via JS interface. Is there any way for CCT?
Based on Can I Inject Javascript Code into Chrome Custom Tabs the answer appears to be no.
Chrome Custom Tab is based on Chrome itself and has the same security model. The web content is only allowed access to the Web APIs (camera, device orientation, etc.) and has no access to the native app. At best the native app can capture a URI.
Even the Chrome Custom Tab documentation state that the way for a native app to handle content:
Some URLs can be handled by native applications. If the user has the Twitter app installed and clicks on a link to a tweet. She expects that the Twitter application will handle it.
Before opening an url from your application, check if a native alternative is available and use it.
Implies that either a native app handles a URL or not. My interpretation of Chrome Custom Tab is a skinnable Chrome component adjacent to the native app rather than internal to a native app like a WebView where a Javascript bridge exists.
Your desire for a Javascript bridge from a web app would mean that there would be a arbitrary way for any website code to interact outside of the web container. The rational as to why that is not allowed is given as the responses in the first link.
I'm making a Native Messaging extension in firefox, I have some question:
Background-script (addded by background key) and content-script (added by content-script key). What's different between them and can I use both of them with 1 JS file? If not, I have to send page-script->content-script->background-script->native-app?
Which's the best function I need to use to send message from page-script to native app? I followed this example or tried with this function but it doesn't work.
Background-script can be considered as long term running, since Firefox started, to Firefox process quit. While content scripts runs in web page context, ends when web page closed. Content scripts can be used to access/modify web page, while background script can't. For detail, see documentation of background scripts, content scripts.
You need Native Messaging to send message from extension to native app. In extension, use chrome.runtime.connectNative to connect to native app. It will return a chrome.runtime.Port object. Then use Port.postMessage to communicate with native app.
Reference: Full Documentation of Firefox WebExtensions
I have developed a chrome extension which does particular job and tries to connect back to a java desktop application.
Now what I want is, the chrome extension should get enabled only when desktop(java) application is opened and similarly it should get disabled whenever I close the desktop application.
Can I manage this using java?
Or any other way/ CMD is it possible?
Basically, you would need some ways to exchange message between extensions and native apps, for this purpose, there are many optional ways, such as Native Messaging, WebSocket, or simple http server/client.
Depends on what you choose to use, the implementation details may differ. However their ideas are similar:
Start the connection from extension and keep the connection for each side
Save a flag in extension side to mark whether your extension should be enabled
Once the connection is lost, revert the flag and disable the functionality of the extension
I'm trying to develop a Chrome App that will work together with a Chrome Extension that I already created, wherein the Chrome Extension will send information to the Chrome App.
For this communication I thought use the WebSocket locally, in Chrome Extension I managed to make the Client, but now I'm having difficulty in creating the Server in the Chrome App, because I wanted to make as simple as possible without having to install something beyond of the Chrome App.
Among the first Google results there is a sample app from Chrome team: Http WebSocket Server.
You've got to understand that making a server in Chrome Apps is difficult; you are given access to a raw socket, and you need to fully implement the protocol that a particular server must use. Even a HTTP server is non-trivial, WebSockets is even less so.
So: it's possible, but it's not simple unless you're using an existing library.
Just to add to the accepted answer:
There is a Chrome Extension already in the Chrome Web Store: Web Server for Chrome.
And it is opensource: GitHub Link. You can use it as a library to your Chrome App.
Cheers!
We have an hybrid android application. I am trying to navigate from a WebView to a Native context back and forth. Using chrome://inspect/#devices I get to notice that multiple instances of device inspected are detached while one of all would be attached as displayed in chrome.
Referring to SO-28254614, now I have not developed the WebView though, but to what I know about our application the WebView are not designed using Cordova and are in JS.
An the question that I have are :
Why is it so that we see these detached devices on chrome?
Could this be a possibility of a leak in Android WebView?
So the way these web inspectors work is that they use the RemoteDebug Protocol.
This protocol defines the various messages and commands that are exchanged to let you 'inspect' your pages.
One instance of the inspector can only connect to one client at a time. So assuming that you are switching to and fro web-views and native context, you are basically spawning new webviews for every new context switch.
This would indicate that the previously opened webviews are now 'orphaned' and for all practical purposes detached.
You can try to inform the VM that a webview is no longer in use by calling destroy() on the webview to let the garbage collector know it is no longer required.
Hope this provides a deeper understanding on what is happening behind the scenes.