-
Notifications
You must be signed in to change notification settings - Fork 3.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
chore: Implement cross-domain sibling iframe #16708
Changes from all commits
0bebd34
79edbd9
911f31e
5a6e98f
d7ced23
2aafbb9
9db015e
4581a76
cdb41e3
15a957a
ab135fc
a57870a
ee7c86c
7125dd7
44168ca
8dd089d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,21 @@ | ||
// NOTE: this test only exists for manual verification as the | ||
// multidomain bundle is a very incomplete work-in-progress | ||
it('loads multidomain playground', () => { | ||
// FIXME: Skip this for now since it's flaky | ||
it.skip('verifies initial implementation of sibling iframe and switchToDomain', (done) => { | ||
top.addEventListener('message', (event) => { | ||
if (event.data && event.data.text) { | ||
expect(event.data.text).to.equal('Some text in the cross-domain AUT') | ||
expect(event.data.host).to.equal('localhost:3501') | ||
done() | ||
} | ||
}, false) | ||
|
||
cy.viewport(900, 300) | ||
cy.visit('/fixtures/multidomain.html') | ||
cy.get('a').click() | ||
// @ts-ignore | ||
cy.switchToDomain('localhost:3501', () => { | ||
// @ts-ignore | ||
cy.now('get', 'p').then(($el) => { | ||
top.postMessage({ host: location.host, text: $el.text() }, '*') | ||
}) | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export function addCommands (Commands, Cypress: Cypress.Cypress, cy: Cypress.cy, state: Cypress.State) { | ||
Commands.addAll({ | ||
switchToDomain (domain, fn) { | ||
Cypress.log({ | ||
name: 'switchToDomain', | ||
type: 'parent', | ||
message: domain, | ||
end: true, | ||
}) | ||
|
||
Cypress.action('cy:cross:domain:message', 'run:in:domain', fn.toString()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it will be addressed in future work. This is a bare-minimum version of this command just to get things rolling. |
||
}, | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ const driverToReporterEvents = 'paused before:firefox:force:gc after:firefox:for | |
const driverToLocalAndReporterEvents = 'run:start run:end'.split(' ') | ||
const driverToSocketEvents = 'backend:request automation:request mocha recorder:frame'.split(' ') | ||
const driverTestEvents = 'test:before:run:async test:after:run'.split(' ') | ||
const driverToLocalEvents = 'viewport:changed config stop url:changed page:loading visit:failed'.split(' ') | ||
const driverToLocalEvents = 'viewport:changed config stop url:changed page:loading visit:failed switch:domain'.split(' ') | ||
const socketRerunEvents = 'runner:restart'.split(' ') | ||
const socketToDriverEvents = 'net:event script:error'.split(' ') | ||
const localToReporterEvents = 'reporter:log:add reporter:log:state:changed reporter:log:remove'.split(' ') | ||
|
@@ -278,6 +278,20 @@ const eventManager = { | |
this._clearAllCookies() | ||
this._setUnload() | ||
}) | ||
|
||
top.addEventListener('message', (event) => { | ||
switch (event.data) { | ||
case 'app:cross:domain:window:load': | ||
return Cypress.action('app:cross:domain:window:load') | ||
case 'cross:domain:driver:ready': | ||
this.crossDomainDriverWindow = event.source | ||
|
||
return Cypress.action('runner:cross:domain:driver:ready') | ||
default: | ||
// eslint-disable-next-line no-console | ||
console.log('Unknown postMessage:', event.data) | ||
Comment on lines
+291
to
+292
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the reason to not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is another bare-minimum implementation to get the ball rolling. We're planning more work on this in the future to put more thought into it and flesh it out more. |
||
} | ||
}, false) | ||
}, | ||
|
||
start (config) { | ||
|
@@ -471,6 +485,10 @@ const eventManager = { | |
studioRecorder.testFailed() | ||
} | ||
}) | ||
|
||
Cypress.on('cross:domain:message', (message, data) => { | ||
this.crossDomainDriverWindow.postMessage({ message, data }, '*') | ||
}) | ||
}, | ||
|
||
_runDriver (state) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>{{title}}</title> | ||
</head> | ||
<body> | ||
<script type="text/javascript"> | ||
document.domain = '{{domain}}'; | ||
</script> | ||
<script src="/__cypress/runner/cypress_multidomain_runner.js"></script> | ||
</body> | ||
</html> |
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.
what's the difference b/t this and autoEnd? same comment
i think you can also update this in
packages/driver/types/internal-types.d.ts
if you don't want it to be publicThere 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.
From what I can tell,
autoEnd
is redundant and we don't actually use it at all. The only instance of it is here:cypress/packages/driver/src/cy/commands/debugging.js
Lines 58 to 61 in e0c385e
However, using
autoEnd
requires callinglog.finish()
:cypress/packages/driver/src/cypress/log.js
Lines 443 to 451 in e0c385e
But I can't find any instances of calling
log.finish()
and the instance from above that usesautoEnd: true
callslog.end()
, which is the imperative way to end the snapshot, indicating it was never the intention to "auto-end" the log forcy.pause()
:cypress/packages/driver/src/cy/commands/debugging.js
Lines 74 to 76 in e0c385e
The
autoEnd
option can probably be removed entirely, but that's outside the scope of this PR. I added theend
option to the types since it's the one we actually use around the codebase for auto-ending a log. I guess this was the first time it was used in TypeScript though, so we hadn't noticed the omission before.