Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Commit

Permalink
Add window.location check for crossorigin attr logic
Browse files Browse the repository at this point in the history
  • Loading branch information
rtsao committed Apr 11, 2018
1 parent 3b621e7 commit 164b1ec
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions build/crossorigin-auto-attribute-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
* As a result of this, any chunks loaded by webpack will fail in Safari
* if they require cookies to be sent (because webpack uses crossorigin="anonymous").
*
* This plugin ensures that the crossorigin attribute is omitted
* unless the script src begins with `https://`.
* This plugin ensures that the crossorigin attribute is omitted if the script
* src matches the page origin.
*
* Note: if for some reason an absolute path is used even for same-origin scripts,
* cookies may be erronously not be sent in Safari.
* Note: `script.src` accesses the `src` property
* (as opposed to attribute) which yields an absolute URL per HTML5 spec
*/

class CrossoriginAutoAttributePlugin {
Expand All @@ -29,7 +29,7 @@ class CrossoriginAutoAttributePlugin {
source => {
return source.replace(
/script\.src = [^;]*;/,
'$& if (!script.src.match(/^https:\\/\\//)) {script.crossOrigin = void 0;}'
'$& if (script.src.indexOf(window.location.origin === 0) {script.crossOrigin = void 0;}'
);
}
);
Expand Down

0 comments on commit 164b1ec

Please sign in to comment.