'chrome.sockets.tcp' in a PWA? - javascript

I am creating a PWA using Nuxt and I want to use the Chrome TCP API to communicate with TCP devices directly. The API is detailed here https://developer.chrome.com/apps/sockets_tcp
I have confirmed that clients are downloading it when they access the page.
manifest.json
{
"name":"pwa-demo",
"short_name":"pwa-demo",
"description":"Test App",
"publicPath":"//_nuxt/",
"icons":[
{
"src":"/_nuxt/icons/icon_64.fj_mLYH_Zr_.png",
"sizes":"64x64",
"type":"image/png"
}
],
"start_url":"/?standalone=true",
"display":"standalone",
"background_color":"#ffffff",
"theme_color":false,
"lang":"en",
"sockets":{
"tcp":{
"connect":[
"*:8023"
]
}
}
}
However, when the PWA is run in the browser or after installation (both on desktop and Android) in all cases I get the following error trying to call a chrome.sockets.tcp API: TypeError: Cannot read property 'tcp' of undefined
The Chrome "apps" API (https://developer.chrome.com/apps) does seem to suggest that it is meant to be done using Cordova but I figured that that suggestion was old (there's other content on the page from 2014) and that once a PWA is installed there shouldn't be a functional difference between an installed Cordova app and a new installed PWA. They're both wrappers around a Chrome WebView (except of course Cordova can expose more native APIs).
I am guessing that the chrome.sockets.tcp API is actually exposed through the Cordova wrapper and not Chrome itself, but I have not found anything that confirms this. Google has publicly expressed that they want PWAs to replace Chrome Apps so one would hope that the API was moved into Chrome itself. There seems to be a lot of people confused about whether it can be used by Chrome extensions too.
Is my manifest wrong? Or can someone confirm that this API is not usable by PWAs?

Chrome Apps are specialized apps that are distributed through the Chrome Web Store. Think browser extensions but more app like. Websites do not have access to the privileged APIs available to Chrome Apps.
Also note that Chrome Apps are being retired for everything other than Chrome OS.

Related

Writing chrome extension to control serial port

I want to write a chrome extension (not chrome app) to control serial port but chrome extension doesnt provide any api to access it.
Because chrome doesnt give permission to direct access the port, I thought I can write C code that control the serial port and then I use this C code in the extension. I found several method to use C codes in the chrome extension. These are;
Pepper api
Emscripten
Native communication
I dont want to use native communication because it requires third party apps.
Emscripten is a tool that convert c code to javascript code. But I cant access the serial port on windows because it doesnt support platform-specific code such as "Windows.h"
Pepper api is part of the chrome development tools but I cant see any api that can access the serial port. Maybe I miss something that can be useful.
Are there any way to control serial port in the chrome extension without using third party app or using chrome app.
You can use the chrome.runtime.connect API to connect your chrome extension to a chrome app. You can then have the chrome app do the serial work, while still being able to access the interface (or whatever your plans are with the chrome extension) in that chrome extension.
This does require both the chrome extension and the chrome app to be installed but it does achieve your goal.

IPSec VPN Client in Java Script using Chrome's "networkingPrivate" API

I want to add VPN client support to an existing chrome extension. I noticed that chrome has an API named 'networkingPrivate' for many network configurations. I kick started with a java script that calls some of the methods provided by networkingPrivate API. But, I'm facing chrome.networkingPrivate 'undefined' error. Any reference on how to use the API in a chrome extension would be of great help!
Chrome OS only, kiosk apps only (not extensions), dev channel only, and it is being renamed.
https://developer.chrome.com/apps/networking_onc
You probably want chrome.vpnProvider instead anyway, but that's still Chrome OS only.

Is the Chrome FileSystem API only available for Chrome Apps (from Chrome Web Store)?

I downloaded the Chrome App samples from https://github.com/GoogleChrome/chrome-app-samples and tried running the FileSystem sample.
The code works when installed from Chrome Web Store, but I'm interested to know whether the FileSystem API can be made to work for non-Chrome-app cases. A simple experiment trying loading index.html on localhost served by my local Apache webserver exhibits a failure because chrome.filesystem is undefined.
Is Chrome Filesystem intended only for Chrome Apps (I can see that clues might be in the name of the samples repo and the fact that it uses a manifest.json) or is there a way of making it work for general (non-Chrome-app) web applications?
Thanks
Is Chrome Filesystem intended only for Chrome Apps
Yes.
is there a way of making it work for general (non-Chrome-app) web applications?
No. Normal web applications are subject to many security limitations (because you "install" them by visiting a webpage).
A simple experiment trying loading index.html on localhost served by my local Apache webserver
Loading resources over HTTP can be done using the XMLHttpRequest object. No escalated privileges on the client required.

Possible to use Google Play Game Services from origin file:///android_asset

Crosswalk is an excellent wrapper to allow HTML5 games to be packaged as native Android apps. You upload your HTML, JS and CSS files and it wraps it with Chromium for Android and builds an APK. It has full GPU support including WebGL, making it far better than PhoneGap.
I want to use the Google Play Game Services web API in a Crosswalk app, but it appears Crosswalk runs from the origin file:///android_asset. E.g. the main page will run from file:///android_asset/www/index.html.
It does not appear possible to allow Crosswalk apps to use the web API. The API console rejects file:///android_asset as an "invalid URI". Is there any workaround to this? Crosswalk is the only sensible way to publish HTML5 games as native apps on Android, and it's a shame if we can't use Google Play services!
The JavaScript code is limited by the same-origin policy, so you cannot access the Google play services(https://www.googleapis.com/*) from the origin file:///android_asset.
But Crosswalk has provided the solution for the cross-origin xhr, you can easily achieve that via adding the following configure to the manifest of your app.
{
...
"xwalk_hosts": [
"http://www.host-you-want-to-go.com/*"
],
...
}
More details in wiki.
You must try it in the latest beta version of Crosswalk, 6.35.131.5.
You can also ask the help about Crosswalk on the crosswalk-help#lists.crosswalk-project.org, in which you could get more faster response.
I wrote a simple example that accesses google play game services with cordova and crosswalk. See https://github.com/rscohn2/phonegapi
With cordova, you can create a browser window for the login, and give http://localhost as the redirect URI. After a successful login, it redirects to http://localhost,
which is not present. The app detects that the browser window has redirected. It reads the access code, then closes the window before the user can see the error.

Javascript : Run client side EXE by CHROME [duplicate]

My requirement is to launch my installed application from chrome browser if it is installed on client machine, If not installed then I wanted to start download. What is best recommended solution for chrome?
So fare i tried following
used NPAPI, but due to deprecation of NPAPI by chrome I can't use.
Checked PNacl and Pepper API both API not providing access to local file system to launch an application. They just port my C/C++ code in browser and run it in browser environment with sandbox restrictions.
Is it true only option i have is to use native messaging? Or is there any other option for simple task to launch my application from our url,
Regarding “Native Messaging”
Do users need to install my extension
Do i need to add my extension to chrome store
How to deal with Registry permissions for non admin users
Can i install extension to chrome along with my app installation
Note :- Found some providers use “External Protocol Request” to launch application but there are no enough resources where can i found more about this
Thanks and Regards,
Pravin
For what its worth,
see here - http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/api/nativeMessaging/
the README indicates that Native Messaging can now be added even by non-Admins.
But it appears Native Messaging will only work for Extensions: "Extensions can exchange messages with native applications(...)" and I dont imagine you can expect all of your users to do that.
To open it if it's installed you just need to register your application (at the OS level, so the details will vary by OS; you don't say what OS you are targeting) as a handler for some specific scheme, then have your page open that scheme. That's the same flow that causes mailto: links to open a user's mail client, for instance.
If you have a chrome app, you can use inline install: https://developer.chrome.com/webstore/inline_installation

Categories