目录

Resolving Cross-Origin Resource Access

Background

For security purposes, the ArkWeb kernel does not allow the file and resource protocols to access cross-origin requests. As such, the Web component blocks such requests when loading local offline resources. To allow cross-origin requests using the file, you can use method 2 to set a path list. When Web components cannot access local cross-origin resources, the DevTools console displays the following error message:

Access to script at 'xxx' from origin 'xxx' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, arkweb, data, chrome-extension, chrome, https, chrome-untrusted.

Solutions to Local Cross-Origin Resource Access

// main/resources/resfile/js/script.js
const body = document.body;
const element = document.createElement('div');
element.textContent = 'success';
body.appendChild(element);