Created
April 8, 2016 04:52
-
-
Save dpogue/d3e2a66a0fb9edd02e1fd2bc17e36012 to your computer and use it in GitHub Desktop.
Very basic proof of concept.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version='1.0' encoding='utf-8'?> | |
<widget id="io.cordova.hellocordova" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> | |
<!-- ... --> | |
<feature name="Manifest"> | |
<param name="android-package" value="io.cordova.hellocordova.ManifestPlugin" /> | |
<param name="onload" value="true" /> | |
</feature> | |
<!-- ... --> | |
<content src="https://dpogue.ca/index.html" /> | |
</widget> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.cordova.hellocordova; | |
import android.net.Uri; | |
import org.apache.cordova.*; | |
public class ManifestPlugin extends CordovaPlugin { | |
private static final String LOG_TAG = "ManifestPlugin"; | |
private static final String SCOPE = "https://dpogue.ca/"; | |
@Override | |
public Uri remapUri(Uri uri) { | |
if (!uri.toString().startsWith(SCOPE)) { | |
return null; | |
} | |
LOG.d(LOG_TAG, "Remapping URI: " + uri.toString()); | |
String remapped = uri.toString().replace(SCOPE, "file:///android_asset/www/"); | |
return Uri.parse(remapped); | |
} | |
@Override | |
public Boolean shouldAllowRequest(String url) { | |
if (url.startsWith(SCOPE)) { | |
return true; | |
} | |
return null; | |
} | |
@Override | |
public Boolean shouldAllowNavigation(String url) { | |
if (url.startsWith(SCOPE)) { | |
return true; | |
} | |
return null; | |
} | |
} |
Hi Manuel, I see you never got an answer but did you ever successfully jerry-rig a service worker?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Dpogue,
I've tried using your gist to load a service worker from file:/// with a fresh Cordova application and a local plugin with your ManifestPlugin.java. The plugin is correctly mapping the external https:// URI to the file:/// protocol, but the service workers still fails to register.
The error I receive is quite general:
Can you shed some light on this?
Manuel