Chrome apps command line arguments

974 views
Skip to first unread message

Ramsundar Kandasamy

unread,
Oct 26, 2016, 7:36:14 PM10/26/16
to apps-dev
Hi,


Does a chrome app allow to read command line arguments?

e.g. "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --profile-directory=Default --app-id=llllllllllllll "MyName" "Address"

Is it possible to get the "MyName" and "Address" in the app's javascript layer?

Thanks!
Ram

Antony Sargent

unread,
Oct 27, 2016, 12:22:08 PM10/27/16
to Ramsundar Kandasamy, apps-dev
In general, no. Also, note that chrome packaged apps on platforms other than ChromeOS (eg windows, osx, linux) are being slowly phased out:



If the thing you're building makes sense as an extension, you can probably take advantage of native messaging to get integration with whatever overall system you're building:





Kyle Graehl

unread,
Oct 27, 2016, 12:42:21 PM10/27/16
to Antony Sargent, Ramsundar Kandasamy, apps-dev
chrome.runtime.sendMessage can be called from a website (or another
app) if you setup the manifest to accept the message from the website
and/or other app/extension. If the app is not launched, it will get an
onMessageExternal event which you can use to "launch" your app (e.g.
do the thing your onLaunched event would do)

So you could launch the app by opening a webpage which then messages
the app. Not sure if this fits into your workflow, but just an idea.
> --
> You received this message because you are subscribed to the Google Groups
> "apps-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to apps-dev+u...@chromium.org.

Antony Sargent

unread,
Oct 27, 2016, 2:11:18 PM10/27/16
to Kyle Graehl, Ramsundar Kandasamy, apps-dev
That's a good idea - note that it would require an appropriate "externally_connectable" entry in your manifest: https://developer.chrome.com/extensions/manifest/externally_connectable

Another simple option that would work for an extension, but not a packaged app, is to provide a url on the command line to a page within your extension and provide arguments via url parameters. For example:

<path to chrome.exe> chrome-extension://EXTENSION_ID_HERE/launch.html?somearg=foo&anotherarg=bar

Then in the launch.html page you'd have some javascript that uses something like:

let args = {};
window.location.search.slice(1).split('&').forEach(pair => {
  let keyval = pair.split('=');
  args[unescape(keyval[0])] = unescape(keyval[1]);
});

to extract the key/value pairs. 




Ramsundar Kandasamy

unread,
Oct 27, 2016, 2:22:38 PM10/27/16
to apps-dev, kgr...@gmail.com, krama...@gmail.com
thanks for your inputs...

This should be ok - "So you could launch the app by opening a webpage which then messages the app. Not sure if this fits into your workflow, but just an idea."

will first have to search/read whether it is possible to launch a chrome extension when chrome is not running?

and then have to check whether the (WebRTC) functionalities that I have in my chrome app would run as an extension as well.

Thanks guys!
Ram
Reply all
Reply to author
Forward
0 new messages