Skip to content

Instantly share code, notes, and snippets.

@dpogue
Created April 8, 2016 04:52
Show Gist options
  • Save dpogue/d3e2a66a0fb9edd02e1fd2bc17e36012 to your computer and use it in GitHub Desktop.
Save dpogue/d3e2a66a0fb9edd02e1fd2bc17e36012 to your computer and use it in GitHub Desktop.
Very basic proof of concept.
<?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>
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;
}
}
@ManuelOverdijk
Copy link

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:

The Service Worker security policy prevented an action

Can you shed some light on this?

Manuel

@Textras
Copy link

Textras commented Feb 28, 2018

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