(page: Page)
| 121 | } |
| 122 | |
| 123 | const recordHandshakeOrdering = async (page: Page): Promise<void> => { |
| 124 | await page.addInitScript(() => { |
| 125 | globalThis.__handshakeOrder = []; |
| 126 | const original = EventTarget.prototype.addEventListener; |
| 127 | EventTarget.prototype.addEventListener = function (type, listener, options) { |
| 128 | if (type === "message" && this === window) { |
| 129 | const frame = document.querySelector<HTMLIFrameElement>( |
| 130 | '[data-testid="artifact-shell-frame"]', |
| 131 | ); |
| 132 | // No frame yet is even earlier than about:blank, so it satisfies the |
| 133 | // invariant too; "(none)" keeps that case distinguishable in a failure. |
| 134 | globalThis.__handshakeOrder?.push( |
| 135 | frame ? (frame.contentDocument?.URL ?? "(no document)") : "(none)", |
| 136 | ); |
| 137 | } |
| 138 | return original.call(this, type, listener, options as never); |
| 139 | }; |
| 140 | }); |
| 141 | }; |
| 142 | |
| 143 | const readHandshakeOrdering = (page: Page): Promise<ReadonlyArray<string>> => |
| 144 | page.evaluate(() => globalThis.__handshakeOrder ?? []); |
no test coverage detected