| 4622 | } |
| 4623 | |
| 4624 | async function targetCreatedHandler(page) { |
| 4625 | if (!page) return |
| 4626 | this.withinLocator = null |
| 4627 | page.on('load', () => { |
| 4628 | page |
| 4629 | .$('body') |
| 4630 | .catch(() => null) |
| 4631 | .then(async () => { |
| 4632 | if (this.context && this.context._type === 'Frame') { |
| 4633 | // we are inside iframe via Frame object — refresh handle |
| 4634 | const frameEl = await this.context.frameElement() |
| 4635 | this.context = await frameEl.contentFrame() |
| 4636 | this.contextLocator = null |
| 4637 | return |
| 4638 | } |
| 4639 | if (this.context && this.context.constructor && this.context.constructor.name === 'FrameLocator') { |
| 4640 | // we are inside iframe via FrameLocator — keep it across load events |
| 4641 | return |
| 4642 | } |
| 4643 | // if context element was in iframe - keep it |
| 4644 | // if (await this.context.ownerFrame()) return; |
| 4645 | this.context = page |
| 4646 | this.contextLocator = null |
| 4647 | }) |
| 4648 | }) |
| 4649 | page.on('console', msg => { |
| 4650 | if (!consoleLogStore.includes(msg) && this.options.ignoreLog && !this.options.ignoreLog.includes(msg.type())) { |
| 4651 | this.debugSection(`Browser:${ucfirst(msg.type())}`, ((msg.text && msg.text()) || msg._text || '') + msg.args().join(' ')) |
| 4652 | } |
| 4653 | consoleLogStore.add(msg) |
| 4654 | }) |
| 4655 | |
| 4656 | if (this.options.windowSize && this.options.windowSize.indexOf('x') > 0 && this._getType() === 'Browser') { |
| 4657 | try { |
| 4658 | await page.setViewportSize(parseWindowSize(this.options.windowSize)) |
| 4659 | } catch (err) {} |
| 4660 | } |
| 4661 | } |
| 4662 | |
| 4663 | function parseWindowSize(windowSize) { |
| 4664 | if (!windowSize) return { width: 800, height: 600 } |