Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何为在Edge/Safari中工作的Web工作人员设置内容安全策略?_Javascript_Web Worker_Content Security Policy_Nginx Config - Fatal编程技术网

Javascript 如何为在Edge/Safari中工作的Web工作人员设置内容安全策略?

Javascript 如何为在Edge/Safari中工作的Web工作人员设置内容安全策略?,javascript,web-worker,content-security-policy,nginx-config,Javascript,Web Worker,Content Security Policy,Nginx Config,我在尝试使用Web Worker时不断从Edge和Safari返回错误代码:18,SecurityError。不过,Firefox/Chrome的工作人员都很好。我使用的是一个内联worker,我将零依赖数据处理函数传递给它 我的顾客服务提供商: add_header Content-Security-Policy "default-src 'self'; worker-src 'self' 'inline' *.example.com"; 我可以自己添加其他类似于本地样式表和googleap

我在尝试使用Web Worker时不断从Edge和Safari返回错误代码:18,SecurityError。不过,Firefox/Chrome的工作人员都很好。我使用的是一个内联worker,我将零依赖数据处理函数传递给它

我的顾客服务提供商:

add_header Content-Security-Policy "default-src 'self'; worker-src 'self' 'inline' *.example.com";
我可以自己添加其他类似于本地样式表和googleapis.com的好东西,但我很好奇如何让工作人员不抛出安全错误

摘自

Edge为工作进程抛出此错误:

  [object DOMException]: {code: 18, message: "SecurityError", name: 
    "SecurityError"}
    code: 18
    message: "SecurityError"
    name: "SecurityError"

我不确定数据url为什么会导致安全错误,但您可以使用
url.createObjectURL
加载工作脚本,该脚本在Edge中似乎工作正常(我没有在safari中测试)

下面是它的样子:

// Create the worker script as a string
const script = '$$='+asyncFunction+';onmessage='+(e => {
        /* global $$ */

        // Invoking within then() captures exceptions in the supplied async function as rejections
        Promise.resolve(e.data[1]).then(
            v => $$.apply($$, v)
        ).then(
            // success handler - callback(id, SUCCESS(0), result)
            // if `d` is transferable transfer zero-copy
            d => {
                postMessage([e.data[0], 0, d], [d].filter(x => (
                    (x instanceof ArrayBuffer) ||
                    (x instanceof MessagePort) ||
                    (x instanceof ImageBitmap)
                )));
            },
            // error handler - callback(id, ERROR(1), error)
            er => { postMessage([e.data[0], 1, '' + er]); }
        );
    });

// Create a local url to load the worker
const blob = new Blob([script]);
const workerUrl = URL.createObjectURL(blob);
const worker = new Worker(workerUrl);

如果您需要任何澄清,请告诉我

丁丁,胜利者。我这方面的疏忽。谢谢你指出这一点。此外,Edge中不支持ImageBitmap,因此需要将其显示出来。
// Create the worker script as a string
const script = '$$='+asyncFunction+';onmessage='+(e => {
        /* global $$ */

        // Invoking within then() captures exceptions in the supplied async function as rejections
        Promise.resolve(e.data[1]).then(
            v => $$.apply($$, v)
        ).then(
            // success handler - callback(id, SUCCESS(0), result)
            // if `d` is transferable transfer zero-copy
            d => {
                postMessage([e.data[0], 0, d], [d].filter(x => (
                    (x instanceof ArrayBuffer) ||
                    (x instanceof MessagePort) ||
                    (x instanceof ImageBitmap)
                )));
            },
            // error handler - callback(id, ERROR(1), error)
            er => { postMessage([e.data[0], 1, '' + er]); }
        );
    });

// Create a local url to load the worker
const blob = new Blob([script]);
const workerUrl = URL.createObjectURL(blob);
const worker = new Worker(workerUrl);