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