Git Product home page Git Product logo

cordova-plugin-remote-injection's Introduction

Deprecation Notice

As the casual onlooker can tell this repo hasn't been updated in a while. Unfortunately this project is deprecated. If anyone would like to fork it and address issues please do so but PRs won't be reviewed and merged into this repo. Cordova is not simple to test (or at least wasn't when this was maintained) and I don't have the time to contribute to maintaining it.

If the repos is forked and maintained let me know and we'll link to your repo here.

  • Brad Reynolds

The remote injection plugin allows a remote site to interact with cordova's javascript APIs when loaded within your cordova app. When compared with a cordova app that packages its HTML the downside to loading a remote site is if the network is down your app is down. This can be an acceptable trade off if your site has a heavy dependency on web services. The advantage to this approach is the build, deployment, and previous investment of an existing site doesn't need to change and can continue to work for browser based users providing a smooth transition to an app which provides tighter native integration.

Features

  • Injects cordova and installed plugin JS into the webview for any remotely browsed page allowing them the same access to the cordova object and its plugins as a packaged cordova app.
  • After a developer defined interval will prompt the user if the loading of the main site is taking too long. The user's options are to wait or retry. If the user waits the prompt will be displayed again after the developer defined interval. If the site loads while the dialog is displayed the dialog is dismissed.
  • Support for iOS and Android platforms.
  • Supports both UIWebView and WKWebView on iOS out of the box (added in v0.4.0).

Installation

cordova plugin add cordova-plugin-remote-injection

Configuration

Configuration is done via preferences in your config.xml.

CRIInjectFirstFiles

<preference name="CRIInjectFirstFiles" value="www/js/init.js" />
Type
String
Default
none

List of paths to JS files within the project to inject before injecting cordova into the remote site. To inject multiple separate the files with a ",".

CRIPageLoadPromptInterval

<preference name="CRIPageLoadPromptInterval" value="5" />
Type
int
Default
10

If the site hasn't loaded after this interval the user will be provided a choice to continue waiting or to retry loading the site. This is turned on by default. If not wanting the prompt the user set the value to 0.

CRIShowConnectionErrorDialog

<preference name="CRIShowConnectionErrorDialog" value="0" />

iOS only

Type
int
Default
1

By default the iOS app will display a dialog if there is a failure to connect to the site. This creates issues if wanting to use Cordova's ErrorUrl config to handle connection errors. "0" will turn off displaying of the dialog and allow the ErrorUrl config to kick in.

FAQ

1. Will Apple approve the app if it just wraps a site? Point 2.12 in their guidelines states:

2.12 Apps that are not very useful, unique, are simply web sites bundled as Apps, or do not provide any lasting entertainment value may be rejected

I make no promises for your app but our app was approved by Apple and is in the App Store. We feel we enhanced our site with the app and are not simply bundling it. We display the website but also provide notifications to our users for important events, badge count updates for alerts, etc. Our app is also specifically for the customers of our company and not general use so that may have been a factor in their decision although all we can do is speculate.

2. Will the plugin work with CSP?

Content Security Policy (CSP) is a cool thing. For the plugin to work you'll need to allow javascript to be executed and javascript data URIs.

The default policy generated by the cordova CLI will work with this plugin. At the point in time this was written the policy was:

<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">

The key to making the plugin work on Android is to ensure that you allow data URIs to be executed in the origin of which the page is served.

The most restrictive way to specify this is:

script-src 'self' data:;

For more on the topic see issue #6.

Support

Log issues on github and we'll get in contact.

cordova-plugin-remote-injection's People

Contributors

bradleyjames avatar fevxie avatar fredericp avatar hafiz-younas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cordova-plugin-remote-injection's Issues

Content Security Policy violation

When plugin attempts to load the Cordova files, I receive an error:

Refused to load the script
'data:text/javascript;base64,Ly8gUGxhdGZvcm06IGFuZHJvaWQKLy8gYzUxN2NhODExYjQ…'
because it violates the following Content Security Policy directive:
"script-src 'self' 'unsafe-inline' 'unsafe-eval' http://…"

Is there a way to load the cordova apis without changing my csp?

Does not work when following links

This works correctly when the app first loads.

However when the app does try to do a page reload, the next time the injection does not happen.

Any ideas on how to fix that?

UIWebView issue

Plugin is not working any more. Now if I add this plugin to iOS project, I get following error from app store: ITMS-90809: Deprecated API Usage - New apps that use UIWebView are no longer accepted. Instead, use WKWebView for improved security and reliability.

Can you remove UIWebView components from plugin?
Problems are all because of new App store requirements for any future update.

Compile issue on ios

Hi,
First of all, thank you for this plugin. You know how important this is for achieving external site based solution.
The plugin works as expected on cordova Android 5.1.1. However, I got compile error for cordova ios 4.1.1.
I included some error message below.

/Users/digitalsign1/Documents/Stopfinder/Client/cordova/platforms/ios/Stopfinder/Plugins/cordova-plugin-remote-injection/CDVRemoteInjection.m:55:57: error: 
  property 'delegate' not found on object of type 'UIView *'
notificationDelegate.wrappedDelegate = self.webView.delegate;
                                                    ^
/Users/digitalsign1/Documents/Stopfinder/Client/cordova/platforms/ios/Stopfinder/Plugins/cordova-plugin-remote-injection/CDVRemoteInjection.m:56:19: error: 
  no visible @interface for 'UIView' declares the selector 'setDelegate:'
[self.webView setDelegate:notificationDelegate];
 ~~~~~~~~~~~~ ^~~~~~~~~~~
/Users/digitalsign1/Documents/Stopfinder/Client/cordova/platforms/ios/Stopfinder/Plugins/cordova-plugin-remote-injection/CDVRemoteInjection.m:161:23: error: 
  no visible @interface for 'UIView' declares the selector 'reload'
    [self.webView reload];
     ~~~~~~~~~~~~ ^~~~~~

I tried it on Cordova ios 3.9.2 and it works. Is it currently Cordova ios 4+ not supported?

Any idea on the issue I have?
Sincerely,

Immediate injection into page

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.

deviceready has not fired after 5 seconds.

I'm having those erros:

deviceready has not fired after 5 seconds.
Channel not fired: onCordovaConnectionReady
Channel not fired: onFileSystemPathsReady

than when I try to use navigator.camera it doesn't turn on camera at all.

Also, let's say there is page loaded later on with inappbrowser, is there a way to inject cordova.js into that page as well?

PageLoadPrompt doesn't appear

Hi !

I am currently testing your plugin.

I have set my <content src="" /> to a remote website.

The website is loading well.

I have not tested yet to use the Cordova API from my remote JS files.

What I wanted to test first was the "PageLoadPrompt" which is supposed to appear if the remote site can't load.

As I understand, the prompt feature is enabled by default, no need to change the config.xml.

And the default timeout is set to 10 seconds. Am I right ?

So I put my phone in airplaine mode, launch my app, wait for 10 secs, and .... nothing. Grey screen.

Am I missing something ? Do I need to configure something in the config file ?

does this still work with Ios?

I got it running on android but i can't get it to run on ios, I've installed the latest Xcode, but when I start it in the Ios emulator and use safari as debugger cordova is always undefined.

BTW I'm using the latest Xcode and cordova 7.0.1

How do I inject and use cordova plugins ?

After I moved my webview on the server I have many plugins not available.

For some reason there are few that I can access.
cordova.plugins:

Keyboard: function()
brightness: {getBrightness: function, setBrightness: function, setKeepScreenOn: function}
screenorientation:

window.plugins:

orientationLock

In my javascript I have a call to 'window.plugins.streamingMedia.playVideo

How would I make all the cordova plugin available the same way they where previously ?
Can I inject them using this plugin ?

User is left with blank screen if page load takes too long

If the wrapped site is taking too long to respond the user is left with a blank screen. This request is to add a more responsive UI prompting the user to inform them of the state. The user can then either wait or retry the call. The user should always have a way out.

This will only affect the URL of the web view. Any calls made by the site within the web view should handle the behavior according to their own requirements.

navigator.splashscreen not defined

I have

<preference name="AutoHideSplashScreen" value="false" />

and I'm trying to call navigator.splashscreen.hide() from my remote code. Should that work with remote injection? It seems like navigator.splashscreen is undefined when using this plugin.

CRIInjectFirstFiles is not working on IOS with multiple files list

The plugin offer the chance to inject multiple files with the following command tag for the config.xml

<preference name="CRIInjectFirstFiles" value="www/js/dist/vendor.js,www/js/dist/injected.js" />

For Android, everything works fine, javascript is injected into the remote site.
For IOS it is not the case. I can confirm that for already two projects (two different work projects) the second file, maybe also the first but we did not check this scenario, is not injected at all.
The solution of the problem was using just one file, so this

<preference name="CRIInjectFirstFiles" value="www/js/dist/injected.js" />

It works but it is not in line with the docs of the plugin.

Suppressing the "Connection Error - Unable to contact the site." message

On occasion I get a very quick error that says "Connection Error" "Unable to contact the site.". By quick, I mean it flashes for about a second and then disappears and continues loading, like there's nothing wrong. I'm puzzled why it shows up in the first place.

connectionerror

Is there a way of permanently disabling this message? I have CRIPageLoadPromptInterval set to a high value, however that seems to only prolong the "Wait/Retry" message that appears.

A quick search reveals the offending file to be "CDVRemoteInjectionWebViewBaseDelegate.m" in the "ios" directory, so it's presumably an iOS only issue?

UIAlertView Deprecation since iOS9

cordova-plugin-remote-injection/CDVRemoteInjectionWebViewBaseDelegate.m:45:5: 'UIAlertView' is deprecated: first deprecated in iOS 9.0 - UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead

Any chance to tackle this before the next ios kills it?

How to open a URL by using this plugin

In the readme file, it just mentions how to configure the plugin. Still confuse how to use it to open a url like "http://192.168.1.100:8100"

In the config.xml, I put the following line:

<preference name="CRIInjectFirstFiles" value="www/js/openURL.js" />

The openURL.js file opens an url like the following:

var app = {
    // Application Constructor
    initialize: function() {
        document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
    },

    onDeviceReady: function() {
         this.receivedEvent('deviceready');
         window.open('http://192.168.1.100:8100', '_self ', 'location=yes');
     },

     receivedEvent: function(id) {
         var parentElement = document.getElementById(id);
         var listeningElement = parentElement.querySelector('.listening');
         var receivedElement = parentElement.querySelector('.received');
 
         listeningElement.setAttribute('style', 'display:none;');
         receivedElement.setAttribute('style', 'display:block;');
 
         console.log('Received Event: ' + id);
     }
 };

 app.initialize();

'http://192.168.1.100:8100' appoints to an remote ionic/cordova app which gets involved by 'ionic serve --address 192.168.1.100'. Now, I can visit the link from another cordova app on my cell phone. The link will be opened within the cordova app on my cell phone.

The reason for using this plugin:

How to let the remote ionic/cordova app considers itself running on a cell phone instead of a browser. Therefore, the remote ionic/cordova app can use the camera or other equipments of my local cell phone.

android.view.WindowManager$BadTokenException crashes

Hi,

while using the plugin for my app I noticed many crashes from the play console, the error was always this:

android.view.WindowManager$BadTokenException
com.truckmovers.cordova.RemoteInjectionPlugin$UserPromptTask$1.run

details:

android.view.WindowManager$BadTokenException:
at android.view.ViewRootImpl.setView(ViewRootImpl.java:685)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:328)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
at android.app.Dialog.show(Dialog.java:325)
at com.truckmovers.cordova.RemoteInjectionPlugin$UserPromptTask$1.run(RemoteInjectionPlugin.java:312)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5777)
at java.lang.reflect.Method.invoke(Native Method:0)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)

I am using CrossWalk as webview, could this be in any way related?

Issues with custom url scheme

Hey, I'm using this package along with this one to register a custom url scheme with my application. I'm also using appcache to cache all the assets locally on the device.

I'm having an issue that I think might be related to this package -- sometimes when I open the application with a protocol url, the entire app breaks and all I see is a blank white page (I don't even see the index.html file).

One thing I suspect might be happening and I'm curious to hear your input: when I start the app, I sometimes see some error logs and the webpage ends up on about:blank. I think what might be happening is that this plugin tries to inject the cordova scripts on this page even though there's no document or window and so there's an error and it never recovers.

Anyways I'm not sure about this, but its a really had bug for me to track down. I'd appreciate any help or suggestions. I'm able to reproduce it much more frequently in production than locally which is pretty annoying considering I can't see any debug logs in production...

Customisable strings for PageLoadPrompt

Hi

The strings (main text + wait and retry buttons) used in the PageLoadPrompt should be customisable from the config.xml file.

It would allow to translate the prompt in a cleaner and easier way than modifying the Java and Objective C source files.

Roadmap

First off, love the plugin. Glad I stumbled upon it and it has been invaluable for my own project. I was just curious about the roadmap for it? What are your plans for the future? What other features do you think will be coming down the pipe for this?

CRIInjectFirstFiles issue

If I include www/cordova.js in the list of files to inject with CRIInjectFirstFiles I get an error thrown: cordova already defined

If I don't include it I get Uncaught ReferenceError: cordova is not defined

Which is the right way?

Just to add a bit more.... I'm getting no console logs from the index.js file I load. A plugin I have defined is loading (at least the library it includes is loading) and I get this is the console "Could not find cordova.js script tag. Plugin loading may fail" -- however, I can type cordova in the console and it traces ok.

Currently got this

Could not find cordova.js script tag. Plugin loading may fail.

hi,

When I run plugin on cordova 6.3 , cordova android 5.2.1 with remote url which config like this

<content src="https://xxx.com" />. 

The remote web page meet an error:

data:text/javascript;base64,ZnVuY3Rpb24gdGVzdCgpIHsKICAgIGFsZXJ0KCd0ZXN0Jyk7Cn0KLy8gUGxhdGZvcm06IGF…:1920 Could not find. Plugin loading may fail.

@bradleyjames Can you give me some advices.

Thanks.

Problem accessing PhoneGap APIs from remote JS

I'm trying to access PhoneGap plugins from javascript on my remote site but I cant seem to get window.plugins to be anything but undefined. Here's my setup in config.xml:

<content src="https://domain.com/path-to-app " />
<plugin name="cordova-plugin-remote-injection" />
<preference name="CRIPageLoadPromptInterval" value="5" />
<preference name="CRIShowConnectionErrorDialog" value="0" />

I'm getting Uncaught SyntaxError: Invalid or unexpected token in console at the end of the first line:
script.src="data:text/javascript;charset=utf-8;base64,Ly8gUG...

There seems to be a fix for this here: #25. @bradleyjames Can you merge this fix into the main build or is there some other workaround?

I presume that the CRIInjectFirstFiles preference is optional and not required in my case? It's not really clear from the docs what this param is intended for or if it's required.

Adding print code to hosted web app

I'm trying to add printing code to a web app that is hosted in the cordova-plugin-crosswalk-webview using the plugin-remote-injection to connect the event on the app to an alert hosted on the site. Currently I'm just trying to get a response that I've added to the OnDeviceReady method inside the index.js javascript, but the app has now stopped loading the page after displaying the splashscreen. I've added the local javascript to the CSP and also added the js files to load to the config.xml. I was wondering if anyone has had any problems like this in the past. Thanks in advance.

cordova injected multiple times

Whenever I interact with my Android app in a certain way (I can't yet work out what exactly it is) i see "cordova already defined" and new items being added to the bottom of the head element as shown here:
cordova_reloaded

By looking at your code i conclude my webpage/webview (which is crosswalk in my case) generates a multiplicity of (spurious?) 'onPageFinished' events to which your plugin reacts by re-appending the same script over and over again.

Please, lets help each other diagnose this.

Link opens in Safari instead of navigating to it

Hi,
It's me again. Thanks for the 0.2.0 update. It works with all my plugins.

Since I upgrade to cordova ios 4.1.1. I noticed a behavior change, when click on a link (a tag) like this <a href="#">Link</a>, built in safari will be opened instead of navigating the WebView to that page.

I thought this is a easy things to fix but after messing with things like <allow-navigation /> <access origin="*" /> for a while I still can't make this opening safari behavior go away.

This behavior doesn't exist on corodva ios 3.9.2 with previous version of this plugin. This behavior also doesn't exist when not using external website but use traditional 'stuff in www' folder.

Do you any insight on this issue?

Sincerely,

disable CRIPageLoadPromptInterval

Hi again

So sorry to spam your issues list :)

In the documentation, you write this about the CRIPageLoadPromptInterval:

If not wanting the prompt the user set the value to 0.

This is not working on Android (not tested on iOS yet)
When I set it to 0, it just uses a delay of 0, so the prompt appears immediately.

utf-8 support

Hi:

I use this plugin inject a javascript file on the remote website, it worked perfect. But when I write some none ascii chars in the javascript file, on the Android platform, I found the none ascii chars display wrong. I think maybe the problem should be settled on this plugin?

the javascript like :

navigator.notification.alert(
                message,    // message
                null,       // callback
                "", // title
                '确定'        // buttonName
            );

I use none ascii code on the button name, please give me some advices.

Thanks.

injection not working !

in config.xml

 <preference name="AppendUserAgent" value="com.myWebApp" />
<preference name="CRIInjectFirstFiles" value="www/js/init.js" />
<preference name="CRIPageLoadPromptInterval" value="5" />
<preference name="CRIShowConnectionErrorDialog" value="0" />

but remote website cannot load my js filie.
help help

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.