I'm trying to use importScripts
self.addEventListener('fetch', event => {
...
self.importScripts('idb.js');
...
}
to load a library for a service worker for a PWA but keep getting
DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope':
The script at 'http://localhost:3000/idb.js' failed to load.
The script file is there, content type is correct, application/javascript, and I've tried it with text/javascript too. My developer tools network tab shows the request starting and then failing really quickly, not getting a chance to hit the server. The status code is (failed) net::ERR_CONNECTION_REFUSED when over http and (failed) net::ERR_FAILED over https. Any help appreciated
According to https://developers.google.com/web/updates/2018/10/tweaks-to-addAll-importScripts
Prior to Chrome 71, calling importScripts() asynchronously outside of the install handler would work. Starting with Chrome 71, those calls throw a runtime exception (unless the same URL was previously imported in an install handler), matching the behavior in other browsers.
I have to move importScripts to the top level of my file or my install handler and it works
Based upon the link you provided, you are not running under HTTPS. You need a site under HTTPS to use a service worker.
My original post wrong. #kmanzana pointed out that localhost is considered a "secure origin".
Also, if there is an import statement inside any of the scripts on which you are using importScripts(), you will get this error, and it will not immediately be clear why you are getting it. Caveat emptor.
Related
First time using web workers and I get this error when I try to run it.
First I get a very generic error event sent to my worker.onerror handler. It does not have the message property, the only information is the property type which says error.
Looking at the network tab in dev tools, the request for the worker script looks like it succeeds but it only has provisional response headers and no content to preview.
Preview has:
failed to load response data: connection is closed, can't dispatch pending call to Network.getResponseBody
This caused me to waste about an hour searching for web worker errors. Anyway it turns out that you can get this error if you have a syntax error in your Javascript. At least that is what got me.
I'm writing a script that uses an XMLHttpRequest to search for a file defined by a relative path, by attempting to resolve that relative path against other same domain absolute paths that the script is aware of, then attempting to load the file from that resolved url. If I encounter a 404, I just try to resolve the files relative path against another absolute path, and try again. For this particular script, its perfectly fine to encounter a 404- however, my console is littered with 'Failed to load resource: the server responded with a status of 404 (Not Found) messages, and I want to suppress them.
There is no error to catch as far as I can see- error cases are handled by the xmlHttpRequest.onreadystatechange handler, and there is no window.onerror.
Is there any way to suppress these messages?
Thanks
This feature was introduced last year. You can enable it here: DevTools->Settings->General->Console->Hide network messages.
See also Filtering the Console output and Additional settings in the devtools documentation.
Use console.clear() in the catch block or error handler function.
It will clear those request error on the console immediately after it is logged.
PLEASE NOTE
From MDN
Note that in Google Chrome, console.clear() has no effect if the user has selected "Preserve log upon navigation" in the settings.
Read more about it on MDN
try {
var req = new XMLHttpRequest();
req.open('GET', 'https://invalidurl', false);
req.send();
} catch(e) {
console.clear();
}
Should log this
GET https://invalidurl/ net::ERR_NAME_NOT_RESOLVED
but it will be cleared.
If you use a web worker to perform XMLHttpRequest requests, the errors will be logged into the worker script context so they will not appear on the console unless this context will be specifically chosen for display.
I am using PhantomJS 2 and the latest CasperJS to test a remote webpage containing some TypeErrors. While logging into the webapp, a popup.created and popup.loaded event are initiated before PhantomJS prints a stacktrace of TypeErrors found when attempting to render the resource. PhantomJS hangs here because PhantomJS does not know how to handle parse errors (Github issue #10687). And my attempts to listen for "error" and "page.error" in both Phantomjs and Casperjs events fail since these TypeError (parse errors) do not throw page.error events (Github issue #10537). I do not own the remote webapp, so I cannot fix these errors. But I need to catch these remote webpage errors and proceed with my testing.
I have unsuccessfully tried to abort loading the resource when the popup.created and popup.loaded events are initiated and I also unsuccessfully attempted to abort the request for the resource when the url of the requested resource matched known url of the .html popup file with TypeErrors. Does anyone know a better way to handle these TypeErrors?
It seems that IE11 version 11.0.7 (KB2929437 on Win7, KB2919355 on Win 8.1) has a problem when performing an Ajax POST operation. The operation returns status 0 and on an F12 console, the following error appears:
SCRIPT7002: XMLHttpRequest: Network Error 0x2ee4, Could not complete the operation due to error 00002ee4.
The conditions to reproduce this issue are as follows:
Happens only on specific IE11, i.e. version 11.0.7 (KB2929437 on
Win7, KB2919355 on Win 8.1)
iframe is used to load external page with https protocol (parent page is using http protocol)
ajax with method 'POST' is used
More frequently happens with Connection: Keep-Alive header set on by IIS
More frequently happens on Win32 version of IE11
I created the following jsfiddle to reproduce this issue: http://jsfiddle.net/VJ2D6/12/
$(document).ready(function () {
$('#frame').attr('src', 'https://54.249.142.247/ie11/test.html');
});
Please note that the iframe retrieves its source from another site 54.249.142.247 (hosted by EC2 node using IIS7), because jsfiddle doesn't host https.
And, because I am using Self-Sign SSL Certificate, please first install the certificate to the Trusted Root, and turn off "Warn about certificate address mismatch" from Internet Options - Advanced Tab.
Inside 54.249.142.247/ie11/test.html, I created a button which initiates an Ajax POST operation to a non-existing location. Normally this request should return status 404 error (Not found). But in case of IE11 version 11.0.7, it often returns status 0 error and shows Network Error 0x2ee4 inside F12 console, "
I posted the same issue to Microsoft Connect here: https://connect.microsoft.com/IE/feedback/details/877525/ie11-returns-status-0-during-ajax-post-operation-from-an-iframe-xmlhttprequest-network-error-0x2ee4#tabs
I think this is an IE11 bug, but I am not 100% sure and there is no confirmation yet from the IE team. Please help me to confirm whether this is an IE bug, or if there is any problem in my JavaScript code.
UPDATE:
Microsoft said that they can reproduce the problem and will investigate it.
This error is be cause a ssl certificate is invalid. For solve this error see: [Link]
$.get(window.api + 'Values', null, null).done(function () {//solution for IE shit
$.ajax({
type: 'POST',
url: https://api.yourdomain.com,
data: yourData,
success: function (data) {
//do something
},
});
});
I was having the same issue when trying to do a POST call to our HTTPS WCF service (CORS) and looks like it's because of the SSL Certificate.
I had to recreate mine with the following MakeCert Command line
makecert.exe -r -pe -n "CN=*.YourDomain.com" -eku 1.3.6.1.5.5.7.3.1 -ss my -sr localMachine -sky exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -a sha256 -sy 12 "C:\EncryptionCert.cer"
installed the created Cert into Client and server trusted root cert Auth.
After choosing this cert for my Site binding, I was able to successfully call my HTTPS WCF service in IE 11.
I have the same issue too. at first i use make a get request before post. it solve the issue. but when i deep in, i find it's the in the internet option -》 Advanced options
cancel check for server certificate revocation*
cancel check for publisher certificate revocation*
click ok
restart your browser
i resolved the issue
enter image description here
requrl_1 = "http://www.example.com/index.php";
requrl_2 = "http://www.example.com/redirect.php";
when I request "requrl_1", there is no problem. I'm getting response. "index.php" is not a redirector page.
but requrl_2 is a redirector page, that is redirecting to another website(for example: http://www.cnn.com).
so when I request with XMLHttpRequest, I'm getting exception 101 error.
I must request "redirect.php", there isn't another solution.
How can I do that? Why am I getting "exception 101" error.
I'm coding a Greasemonkey userscript script for google chrome.
It's best to just install Tampermonkey and use it to run your script. Then you can code with GM_xmlhttpRequest()Doc -- which has cross-domain support. And scripts get enhanced capabilities to match what Greasemonkey can do on Firefox.
If you don't want to install Tampermonkey, Chrome userscripts now support cross-site requests via GM_xmlhttpRequest().
So, you could use:
GM_xmlhttpRequest ( {
method: "GET",
url: "http://www.example.com/redirect.php",
onload: function (response) {
//-- Do your business here.
}
} );
From the XMLHttpRequest Spec
If something goes wrong (infinite loop, network errors) the state must
be set to loaded and all members (excluding readyState) of the object
must be set to their initial value. Also, if async is set to false, a
NETWORK_ERR exception must be raised. In addition, all registered
event listeners must be removed.
Basically the redirect is causing the same origin policy to be fired. Which is firing the error. The request should be served with a proxy and not a redirect.