12

I'd like to use new APIs provided for Chrome Packaged Apps, but also want to preserve ability to open some local URL in my current browser environment, is it possible? All Packaged Apps tutorials are focused on creating separate window and using app as first class citizen in the system.

Maybe its possible somehow to use chrome.socket and other APIs as usual, probably even only in developer mode?

Nik
  • 9,063
  • 7
  • 66
  • 81

2 Answers2

11

No, it is not possible by design. Chrome packaged apps run separately from the browser and have no access to browser-specific features, like tabs. The closest you can get is to open an external (not in the packaged app) URL in the browser through window.open.

However, you can kind of emulate a browser by using the webview tag. See the code of the Browser sample to learn how to do it.

You can also install an extension that talks to your packaged app using the just released messaging API. See the messaging sample to learn how - it is pretty simple as long as you know the app and the extension IDs.

mangini
  • 4,179
  • 2
  • 19
  • 23
  • Thanks! I thought it was impossible, but hoped there was a workaround. – Nik Jan 16 '13 at 10:58
  • This answer is incorrect. window.open can be used from the background page to allow a packaged app to open in a browser window. – kzahel Jun 04 '15 at 20:03
  • No, it is not incorrect. Packaged apps content cannot open on browser windows. You can open a regular URL using window.open, as I mentioned in my response, but you CANNOT open your app's local content in a browser window unless you use a webview. Maybe you are thinking about the old, deprecated, package apps? (those ran on tabs, not on separate windows) – mangini Jun 08 '15 at 17:32
  • Well regardless of whether this is recommended or documented, it does work, and is indeed used by a very popular app: https://chrome.google.com/webstore/detail/videostream-for-google-ch/cnciopoikihiagdjbjpnocolokfelagl (they needed to run in a browser tab so that they could interoperate with the google cast extension, which surfaces no API to the chrome platform, so it makes sense that they would need to run in a tab) – kzahel Jun 15 '15 at 19:13
  • @kzahel, If I understand VideoStream code correctly, they use a mix of url_handlers and messaging to achieve this. It is neat and it looks like the app's content is running in a tab, but it is not. – mangini Jun 15 '15 at 23:08
  • OK, well I'm just observing that the URL is indeed chrome-extension:// and the fact that I was able to open a tab with resources inside a packaged app. Try window.open from a background page and you'll see that it opens an app window as a browser tab and has full app API permissions. Some things behave strangely, a page reload and browser back button will not work correctly, though. The tab needs to be opened via the background page. – kzahel Jun 16 '15 at 00:06
  • Yes, it is a known issue (https://code.google.com/p/chromium/issues/detail?id=252464) and it will likely be fixed in the future, so I wouldn't rely on that for anything except to satisfy your curiosity :) – mangini Jun 16 '15 at 00:45
  • @mangini, But if we use a webview, there's no way to drag-and-drop tabs over to the main Chrome's windows right? Also, regarding the "messaging technique" you're talking about, is there any way to make the app window "invisible" such that the user only sees the tab (the Chrome extension)? – Pacerier Jun 23 '15 at 01:11
  • 2
    BROKEN LINKS! BROKEN LINKS! – ejbytes Aug 21 '16 at 12:30
4

Edit: this is unsupported/likely to break in Chrome 44/45+ or so. There was around March 3rd a code review which does indeed break window.open from background page, but was reverted temporarily. So expect this to not work starting around Chrome 50?

It actually is possible (in Chrome 43) to run your chrome platform packaged app in a browser tab. From your background page, simply call window.open with a URL of some content in your app. for example if index.html is in your app's directory, it will open your app in a browser tab with URL chrome-extension://{{ extension id }}/index.html

This should not require any extra manifest permissions.

Note that it will not work if you simply type the url chrome-extension://{{ extension id }}/index.html into your browser. You need to open it from the app's background script.

kzahel
  • 2,765
  • 1
  • 22
  • 31
  • Is this still valid? `chrome-extension://{{ asdfsdfsdfsdfsdfsdfsdfsdfsdfdsfsd }}/index.html` That's what an ID looks like about 30 characters. So enter it like this? Verbatim with no quotes and slashes? – ejbytes Aug 21 '16 at 12:32