TruckMovers / cordova-plugin-remote-injection

DEPRECATED: Cordova plugin to allow a remote site to interact with cordova's javascript APIs when loaded within a cordova app.
Apache License 2.0
91 stars 95 forks source link

Immediate injection into page #18

Open Jammmmm opened 7 years ago

Jammmmm commented 7 years ago

Is it possible to have this plugin inject as soon as possible into a page? At the moment it seems to wait a while, though I'm not sure exactly how long (document ready perhaps?). I would love to be able to inject some Javascript as soon as the tag is detected, or perhaps after a given timeout after the page has begun displaying.

bradleyjames commented 7 years ago

There may be something we could do here in the plugin but have you tried profiling your page and figuring out why it appears to be injected late in the process? The native plugin only has hooks into life cycle events provided by the webview control provided by the platform. The platforms don't expose fine grained events. There could be a way to intercept a call in the webview before the pages lifecycle events are published but I haven't dug into it.

It's not a bad idea but it's probably not something I'll be looking into soon unless there's an large outpouring that this is a high priority issue. Also a PR here would be awesome.

bostondv commented 7 years ago

I'd really like to have this as well, unfortunately I don't know enough to recommend a solution.

From my experience the script injection is not executed until my remote page has fully loaded. This is not ideal as the page has already rendered by the time "deviceready" is fired and makes it impossible to check for and run any conditional cordova code before the page is displayed.

ccorcos commented 6 years ago

@bradleyjames I've toyed around with this and it appears that the injected javascript only gets evaluated after the page loads.

My current solution right now is to override the User Agent and test that to see if the application is running in Cordova so that I can wait for device ready. But that's ugly and now I cant use the user agent to detect the type of device...