Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

iOS: x-local doesn't work on remote pages over https. #70

Open
m-abs opened this issue Apr 17, 2020 · 1 comment
Open

iOS: x-local doesn't work on remote pages over https. #70

m-abs opened this issue Apr 17, 2020 · 1 comment
Labels
bug Something isn't working ios

Comments

@m-abs
Copy link
Contributor

m-abs commented Apr 17, 2020

WKWebView considers the x-local scheme insecure, when the page is loaded via HTTPS and refuses to load local files via x-local.

Workaround:
Use autoLoadJavaScriptFile or autoLoadStyleSheetFile before loading the webpage.
This will generate at WKUserScript that doesn't have the same restrictions.

Alternativ for javascript files.

            const elId = resourceName.replace(/^[:]*:\/\//, "").replace(/[^a-z0-9]/g, "");
            const sourceCode = await fs.File.fromPath(this.resolveLocalResourceFilePath(path) as string).readText();

             const scriptCode = `window.nsWebViewBridge.injectJavaScript(${JSON.stringify(elId)}, ${JSON.stringify(sourceCode)});`;

            webview.executeJavaScript(scriptCode, false);

Alternative for CSS files.

            const elId = resourceName.replace(/^[:]*:\/\//, "").replace(/[^a-z0-9]/g, "");
            const sourceCode = await fs.File.fromPath(this.resolveLocalResourceFilePath(path) as string).readText();

             const scriptCode = `window.nsWebViewBridge.injectStyleSheet(${JSON.stringify(elId)}, ${JSON.stringify(sourceCode)});`;

            webview.executeJavaScript(scriptCode, false);

No known workaround for other filetypes.

I'm working on a solution, but I cannot promise when I can have it solved.

@m-abs m-abs added bug Something isn't working ios labels Apr 17, 2020
@ray007
Copy link

ray007 commented Aug 12, 2020

I'm having a problem with loading data from x-local with the contents of my webview being loaded from file://.
And the x-local load fails silently, neither onload nor onerror of the XmlHttpRequest seem to get called.
Is this the same error?

Directly loading the data with file:// from a subfolder of knownFolders.documents() also didn't work

Edit: onreadystatechange() does work, so not the same problem.
Edit2: fetch() does not work

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working ios
Projects
None yet
Development

No branches or pull requests

2 participants