Skip to content
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

nodom: workerDOM should be document.defaultView #1091

Merged
merged 2 commits into from
Sep 9, 2021
Merged

Conversation

samouri
Copy link
Member

@samouri samouri commented Sep 8, 2021

summary
Fixes ampproject/amphtml#35902

  1. Renames DocumentLite.ts to DocumentStub.ts. The filename should match the exported class :)
  2. Modifies workerDOM export to actually be the document.defaultView which is essential for propagating properties (localStorage/sessionStorate) to the global self. This is also how the regular binary works. See below snippets

Object.keys(workerDOM).forEach(function(k){self[k]=workerDOM[k]});

return document.defaultView;

testing done
Copied the built binaries over to a local amphtml and confirmed that localStorage access was available on self

@samouri samouri changed the title DocumentLite rename, Use real global nodom: workerDOM should be document.defaultView Sep 8, 2021
@samouri samouri self-assigned this Sep 8, 2021
@samouri samouri marked this pull request as ready for review September 8, 2021 15:58
@rcebulko
Copy link
Collaborator

rcebulko commented Sep 8, 2021

Object.keys(workerDOM).forEach(function(k){self[k]=workerDOM[k]});

Why can't this be Object.assign(self, workerDOM);?

@samouri
Copy link
Member Author

samouri commented Sep 8, 2021

Object.keys(workerDOM).forEach(function(k){self[k]=workerDOM[k]});

Why can't this be Object.assign(self, workerDOM);?

Probably can be! Feel free to make a separate PR!

@samouri samouri merged commit b2363aa into main Sep 9, 2021
@samouri samouri deleted the docstub-window branch September 9, 2021 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot access localstorage from amp-script using sandboxed mode
2 participants