-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.. Uncaught (in promise) Error: Browser-only version of superagent could not find XHR #1731
Comments
As a workaround, reverting to 7.1.5 will do the job: Replace the line There seems to be a bug that came in with the newest version (7.1.6) in the method line in 7.1.5: I got the error while trying to use superagent in my electron app. The main file is loaded via file protocol, up until 7.1.5 the condition would evaluate to true and I could use the standard XMLHttpRequest. Now, I am getting the same error as HorrorBest. Is there a reason why documents loaded with the file: protocol are being blocked? Or was that an unintended consequence? |
It is most likely due to if (
root.XMLHttpRequest &&
(!root.location ||
root.location.protocol !== 'file:' ||
!root.ActiveXObject)
root.location.protocol !== 'file:')
) {
return new XMLHttpRequest(); This is the code in question. In v7.1.6 the line The value of root is determined here: let root;
if (typeof window !== 'undefined') {
// Browser window
root = window;
} else if (typeof self === 'undefined') {
// Other environments
console.warn(
'Using browser-only version of superagent in non-browser environment'
);
root = this;
} else {
// Web Worker
root = self;
} |
Is it possible you can evaluate that code block in Electron and try to debug what's wrong here? |
This test seems to work OK without throwing an error: https://jsfiddle.net/6edrz78y/ |
We've tested locally the issue with Electron and confirmed it. Thanks for reporting this. We are going to deprecate v7.1.6 and release v7.1.7 shortly. |
v7.1.6 has been deprecated as it should have been a major semver release anyways. We are releasing v8.0.0 shortly. |
Just tested v8.0.0 locally with Electron, works fine! |
Updated to 8.0.0, works flawlessly in my environment, too. Thank you very much for your work. :) |
Are you going to release the v7.1.7? The package.json file with: gives the error:
I still need IE support. |
Doesn't look like 7.1.7 is released. If you require IE support, you'll have to lock the dependency to 7.1.5. |
I got this error in console while I Was working on something... "Uncaught (in promise) Error: Browser-only version of superagent could not find XHR"
I was using SuperAgent without any other things (bundles/js script) that depend on it... and This is my code if needed
NOTE: I need it to be used in browser (not use Node JS) also I used the Polyfill that I got from the wiki and I got the same error
HTML:
<script src="https://cdn.jsdelivr.net/npm/[email protected]/polyfill.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/superagent.js"></script>
JS FILE:
const server = async () => {
let serverlist = await
superagent.post('request adresse')
.send({email: '[email protected]', password: 'password1234'})
.set('content-type', 'application/x-www-form-urlencoded; charset=UTF-8');
console.log(serverlist.text);
}
server();
NOTE: Email and Password are fake here In the real code I got a real email and password.
The text was updated successfully, but these errors were encountered: