0

We are trying to use Cobalt (20.stable) browser as the browser of our web SPA application. My requirement is to be able to change URL at runtime, what I was able to find in the code: Is:

  starboard::shared::starboard::Application::Link(const char* link_data)

which ends up sending:

 kSbEventTypeLink

Unfortunately this is not working, as code is ignoring the call; the handling reaches the point:

  // TODO: Remove this when terminal application states are properly handled.
  if (deep_link_event->IsH5vccLink()) {
    browser_module_->Navigate(GURL(deep_link_event->link()));
  }

In my case I m trying to change the URL to let say https://www.example.com. There should be a way to do that as when navigating we can always have a link that will cause the browser to go to some URL?

meodou
  • 49
  • 4

4 Answers4

0

Porting layer is not supposed to control navigation directly. Instead, your Starboard implementation may send a deep link event which could be intercepted by a web app which will perform a navigation. See h5vcc_runtime.idl for Web API.

That said, if you are building an SPA, why do you even need to change a URL? Initial URL of a web app is controlled by --url command line switch.

mmotorny
  • 320
  • 1
  • 7
  • Thanks! > Starboard implementation may send a deep link event | That what I did, but in my case I m setting URL: https://www.example.com This ends up it the code I mentioned above, checking IsH5vccLink() and call Navigate(). For https://www.google.com, IsH5vccLink() is false, and the navigation is not done (Deeplink event is ignored). Should I make H5vccLink out of https://www.example.com? Please advice > why do you even need to change a URL?| For development purpose we need to switch to other urls (other apps) without having to kill the cobalt browser and start an new one with new URL. – meodou Jan 30 '20 at 15:15
0

When you say runtime are you looking to change the initial URL when the app is first launched? If so, you could just use the --url parameter.

So you could do the following: cobalt --url="https://www.example.com"

  • I want to do that after the application is started. Let say I start with: cobalt --url="https://www.app1.com". Then later in my App1 I wont to switch to another https://www.app2.com. (just if there is a link with href="https://www.app2.com" is clicked). Posting a deeplinkEvent with https://www.app2.com, is ignored due the the failing IsH5vccLink() test. (Forcing a Navigate() call gives nothing). – meodou Jan 30 '20 at 15:26
0

I did a patch to allow changing the URL. I just need to call starboard::shared::starboard::Application::Link("https://www.example.com"). Inside this call a DeepLinkEvent is posted. Patch : https://gofile.io/?c=9GvNHX

meodou
  • 49
  • 4
0

Cobalt does not navigate for you. The JavaScript receives the deeplink with the function it sets on h5vcc.runtime.onDeepLink and then does whatever it wants with that. As a SPA, it will parse the URL and load new content from its server in its own internal data format (e.g. protocol buffers, JSON, etc.) which it uses to update its own DOM to show new content.

Navigating is not the point of a SPA since that makes it not be a single page application. However, there may be cases such as a loader app that will want to make some initial decisions then load the actual SPA. That loader app would have to have the appropriate CSP rules in place, then set window.location to the URL of the page to navigate to.

Note: The code you found in Application::OnDeepLinkEvent() is a remnant that previously supported the H5vccURLHandler, which was removed in Cobalt 20. It's not meant to navigate to arbitrary deeplinks.

TomB
  • 61
  • 1
  • 3