jpiasetz
jpiasetz

Reputation: 1772

Using a web worker in a local file webview

Is it possible to use a web worker in a local html page loaded in a web view? I've got the webview setup like this

        WebSettings webSettings = myWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setDomStorageEnabled(true);
        webSettings.setDatabaseEnabled(true);
        webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);

        myWebView.addJavascriptInterface(new WebAppInterface(this), "AndroidApp");


        myWebView.loadUrl("file:///android_asset/popup.html");

But in the console I'm getting security warnings:

08-14 19:23:32.981    2042-2042/com.app.androidapp I/chromium﹕ [INFO:CONSOLE(50)] "Uncaught SecurityError: Failed to construct 'Worker': Script at 'file:///android_asset/js/worker.js' cannot be accessed from origin 'null'.", source: file:///android_asset/js/main.js (50)

Upvotes: 1

Views: 3120

Answers (1)

Mikhail Naganov
Mikhail Naganov

Reputation: 6871

Try enabling file access from file URLs:

webSettings.setAllowFileAccessFromFileURLs(true);

If this doesn't help, then use a local web server, see for example this project: https://github.com/google/webview-local-server

Upvotes: 4

Related Questions