-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Improve error message when window.opener == null
#5340
Conversation
when window.opener == null #5334 (comment)
Diff output filesdiff --git a/packages/@uppy/companion/lib/server/controllers/send-token.js b/packages/@uppy/companion/lib/server/controllers/send-token.js
index 1f0738e..5769dc2 100644
--- a/packages/@uppy/companion/lib/server/controllers/send-token.js
+++ b/packages/@uppy/companion/lib/server/controllers/send-token.js
@@ -13,11 +13,33 @@ const htmlContent = (token, origin) => {
<head>
<meta charset="utf-8" />
<script>
- window.opener.postMessage(${serialize({ token })}, ${serialize(origin)})
- window.close()
+ (function() {
+ 'use strict';
+
+ var data = ${serialize({ token })};
+ var origin = ${serialize(origin)};
+
+ if (window.opener != null) {
+ window.opener.postMessage(data, origin);
+ window.close();
+ } else {
+ // maybe this will work? (note that it's not possible to try/catch this to see whether it worked)
+ window.postMessage(data, origin);
+
+ console.warn('Unable to send the authentication token to the web app. This probably means that the web app was served from a HTTP server that includes the \`Cross-Origin-Opener-Policy: same-origin\` header. Make sure that the Uppy app is served from a server that does not send this header, or set to \`same-origin-allow-popups\`.');
+
+ addEventListener("DOMContentLoaded", function() {
+ document.body.appendChild(document.createTextNode('Something went wrong. Please contact the site administrator. You may now exit this page.'));
+ });
+ }
+ })();
</script>
</head>
- <body></body>
+ <body>
+ <noscript>
+ JavaScript must be enabled for this to work.
+ </noscript>
+ </body>
</html>`;
};
/** |
window.close() | ||
} else { | ||
addEventListener("DOMContentLoaded", () => { | ||
document.body.append(document.createTextNode('Unable to send the authentication token to the web app. This probably means that the web app was served from a HTTP server that includes the \`Cross-Origin-Opener-Policy: same-origin\` header. Make sure that the Uppy app is served from a server that does not send this header, or set to \`same-origin-allow-popups\`.')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
document.body.append(document.createTextNode('Unable to send the authentication token to the web app. This probably means that the web app was served from a HTTP server that includes the \`Cross-Origin-Opener-Policy: same-origin\` header. Make sure that the Uppy app is served from a server that does not send this header, or set to \`same-origin-allow-popups\`.')) | |
document.body.append('Unable to send the authentication token to the web app. Please contact your website administrator and/or try again later.'); | |
console.warn('Failed to postMessage. This probably means that the web app was served from a HTTP server that includes the \`Cross-Origin-Opener-Policy: same-origin\` header. Make sure that the Uppy app is served from a server that does not send this header, or set to \`same-origin-allow-popups\`.')) |
addEventListener("DOMContentLoaded", () => { | ||
document.body.append(document.createTextNode('Unable to send the authentication token to the web app. This probably means that the web app was served from a HTTP server that includes the \`Cross-Origin-Opener-Policy: same-origin\` header. Make sure that the Uppy app is served from a server that does not send this header, or set to \`same-origin-allow-popups\`.')) | ||
}); | ||
} | ||
</script> | ||
</head> | ||
<body></body> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<body></body> | |
<body><noscript>JavaScript is required for this app to work correctly.</noscript></body> |
console.warn('Unable to send the authentication token to the web app. This probably means that the web app was served from a HTTP server that includes the \`Cross-Origin-Opener-Policy: same-origin\` header. Make sure that the Uppy app is served from a server that does not send this header, or set to \`same-origin-allow-popups\`.') | ||
|
||
addEventListener("DOMContentLoaded", () => { | ||
document.body.append(document.createTextNode('Something went wrong. Please contact the site administrator. You may now exit this page.')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
document.body.append(document.createTextNode('Something went wrong. Please contact the site administrator. You may now exit this page.')) | |
document.body.append('Something went wrong. Please contact the site administrator. You may now exit this page.') |
var data = ${serialize({ token })}; | ||
var origin = ${serialize(origin)}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var data = ${serialize({ token })}; | |
var origin = ${serialize(origin)}; | |
(function (data, origin) { | |
'use strict'; |
addEventListener("DOMContentLoaded", () => { | ||
document.body.append(document.createTextNode('Something went wrong. Please contact the site administrator. You may now exit this page.')) | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | |
} | |
})(${serialize({ token })}, ${serialize(origin)}); |
|
||
console.warn('Unable to send the authentication token to the web app. This probably means that the web app was served from a HTTP server that includes the \`Cross-Origin-Opener-Policy: same-origin\` header. Make sure that the Uppy app is served from a server that does not send this header, or set to \`same-origin-allow-popups\`.') | ||
|
||
addEventListener("DOMContentLoaded", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addEventListener("DOMContentLoaded", () => { | |
addEventListener("DOMContentLoaded", function () { |
console.warn('Unable to send the authentication token to the web app. This probably means that the web app was served from a HTTP server that includes the \`Cross-Origin-Opener-Policy: same-origin\` header. Make sure that the Uppy app is served from a server that does not send this header, or set to \`same-origin-allow-popups\`.') | ||
|
||
addEventListener("DOMContentLoaded", () => { | ||
document.body.append(document.createTextNode('Something went wrong. Please contact the site administrator. You may now exit this page.')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
document.body.append(document.createTextNode('Something went wrong. Please contact the site administrator. You may now exit this page.')) | |
document.body.appendChild(document.createTextNode('Something went wrong. Please contact the site administrator. You may now exit this page.')) |
'use strict'; | ||
|
||
function sendToken() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'use strict'; | |
function sendToken() { | |
(function (origin, origin) { | |
'use strict'; |
var data = ${serialize({ token })}; | ||
var origin = ${serialize(origin)}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var data = ${serialize({ token })}; | |
var origin = ${serialize(origin)}; |
|
||
sendToken(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sendToken(); |
| Package | Version | Package | Version | | ---------------- | ------- | ---------------- | ------- | | @uppy/companion | 5.0.3 | @uppy/xhr-upload | 4.0.1 | | @uppy/locales | 4.0.2 | uppy | 4.0.3 | - @uppy/companion: Improve error message when `window.opener == null` (Mikael Finstad / #5340) - @uppy/xhr-upload: correctly type xhrUpload meta (Merlijn Vos / #5344) - meta: fix require path in `upload-to-cdn` (Antoine du Hamel / #5343)
#5334 (comment)