Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

getOrigin issue within iFrames #136

Closed
sntk opened this issue Aug 1, 2018 · 3 comments · Fixed by #175
Closed

getOrigin issue within iFrames #136

sntk opened this issue Aug 1, 2018 · 3 comments · Fixed by #175

Comments

@sntk
Copy link

sntk commented Aug 1, 2018

Reporting a Bug?

Yes.

const getOrigin = href => href.match(/(.*\/\/.*?)(\/|$)/)[1];

Requesting a Feature?

No.

I'm using this component inside a Chrome Extension (in an iframe), the document.referrer returns an empty string which throws a typeError

Uncaught TypeError: Cannot read property '1' of null
    at getOrigin (<anonymous>:1:58)
    at <anonymous>:1:35

Would it be possible to add a check for empty strings?
Repro: http://jsfiddle.net/czm0fqyv/1/

Much appreciated!

@sntk
Copy link
Author

sntk commented Aug 1, 2018

This may not be the most elegant solution, but perhaps

const getOrigin = href => href.length ? href.match(/(.*\/\/.*?)(\/|$)/)[1] : null;

@dtslvr
Copy link

dtslvr commented Aug 3, 2018

Thanks for reporting, I have exactly the same issue inside my Storybook environment.

@came
Copy link

came commented Apr 25, 2019

I have the same issue :(

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants