| 741 | } |
| 742 | |
| 743 | export async function waitForIFrameLoad( |
| 744 | page: puppeteer.Frame | puppeteer.Page, |
| 745 | iframeSelector: string, |
| 746 | timeout = 10000, |
| 747 | ): Promise<puppeteer.Frame> { |
| 748 | const el = await page.waitForSelector(iframeSelector); |
| 749 | if (!el) |
| 750 | throw new Error('Waiting for iframe load has timed out - no element found'); |
| 751 | |
| 752 | let frame = await el.contentFrame(); |
| 753 | if (frame && frame.isDetached()) { |
| 754 | throw new Error( |
| 755 | 'Waiting for iframe load has timed out - frame is detached', |
| 756 | ); |
| 757 | } |
| 758 | if (frame && frame.url() !== '') { |
| 759 | return frame; |
| 760 | } |
| 761 | |
| 762 | await page.$eval( |
| 763 | iframeSelector, |
| 764 | (el, timeout) => { |
| 765 | const p = new Promise((resolve, reject) => { |
| 766 | (el as HTMLIFrameElement).onload = () => { |
| 767 | resolve(el as HTMLIFrameElement); |
| 768 | }; |
| 769 | setTimeout(() => { |
| 770 | reject( |
| 771 | new Error( |
| 772 | 'Waiting for iframe load has timed out - onload not fired', |
| 773 | ), |
| 774 | ); |
| 775 | }, timeout); |
| 776 | }); |
| 777 | return p; |
| 778 | }, |
| 779 | timeout, |
| 780 | ); |
| 781 | |
| 782 | frame = await el.contentFrame(); |
| 783 | if (!frame) |
| 784 | throw new Error('Waiting for iframe load has timed out - no frame found'); |
| 785 | return frame; |
| 786 | } |
| 787 | |
| 788 | export function generateRecordSnippet(options: recordOptions<eventWithTime>) { |
| 789 | return ` |