-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Use unique iframe names based on unique domain #2955
Use unique iframe names based on unique domain #2955
Conversation
Browsers are weird. If an iframe has a `name` attribute, it’s window will be cached. When you click a link, then go back, it will insert the **same** src window into the iframe regardless of a different `src`. Well, that hurts us since we generate a unique domain to load 3p frames. We’ll continue to use an old domain’s window, even though the src points to a new domain. Worse, when we post messages to the 3p frame, we will send it with an origin parsed from the `src` attribute even though that is not the real URL of the frame’s window. Fixes ampproject#2943
Thanks! Please add a test. |
Added. |
resetServiceForTesting(window, 'bootstrapBaseUrl'); | ||
resetCountForTesting(); | ||
const newName = getIframe(window, div).name; | ||
expect(newName).not.to.equal(name); |
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.
It'd be really good to hard code the actual name string in a test.
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.
Added.
677468e
to
da80c87
Compare
@@ -238,4 +245,33 @@ describe('3p-frame', () => { | |||
}; | |||
expect(getSubDomain(fakeWin)).to.equal('d-5670'); | |||
}); | |||
|
|||
it.only('uses a unique name based on domain', () => { |
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.
.only
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.
😔
LGTM |
da80c87
to
29a9b3d
Compare
Browsers are weird. If an iframe has a
name
attribute, it’s windowwill be cached. When you click a link, then go back, it will insert the
same src window into the iframe regardless of a different
src
.Well, that hurts us since we generate a unique domain to load 3p
frames. We’ll continue to use an old domain’s window, even though the
src points to a new domain. Worse, when we post messages to the 3p
frame, we will send it with an origin parsed from the
src
attributeeven though that is not the real URL of the frame’s window.
Fixes #2943.