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