Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught NetworkError: Failed to execute 'importScripts' on 'WorkerGlobalScope'

Tags:

I am trying to import json data from web worker using importSctipts, the following error occurs.

Uncaught NetworkError: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at (my:URL to fetch data from server) failed to load.

Web worker code is here. I am able to send basic messages from my web worker thread and main js thread. I want to fetch jsonp data from my server from web worker thread and then reply to main js thread.

/*web worker js file to fetch json data from server and then return to main javascript thread*/  self.onmessage = function(e) {     var curr = setInterval(function()     {           var message = e.data;                  fetchMyTournament(message);      }, 10000); }    function fetchMyTournament(userid) {     self.postMessage('worker saying hi');       var url = "(server URL mapping)?callback=processInfo&type=(typeOfArgument)&userId="+userid;                   importScripts(url);             self.postMessage("After import script");    } function processInfo(objJSON)  {      self.postMessage("Data returned from the server...: "                    + JSON.stringify(objJSON)); }  
like image 476
user3462649 Avatar asked Jun 22 '14 07:06

user3462649


1 Answers

For my case i was importing PouchDB like this: importScripts("//cdn.jsdelivr.net/pouchdb/5.3.1/pouchdb.min.js");

The url should start with proper http/https. So changing to this solved the problem: importScripts("https://cdn.jsdelivr.net/pouchdb/5.3.1/pouchdb.min.js");

like image 184
nawaz1989 Avatar answered Oct 16 '22 12:10

nawaz1989