* {{> amOnPage }}
(url)
| 1336 | * {{> amOnPage }} |
| 1337 | */ |
| 1338 | async amOnPage(url) { |
| 1339 | if (this.isElectron) { |
| 1340 | throw new Error('Cannot open pages inside an Electron container') |
| 1341 | } |
| 1342 | |
| 1343 | // Prevent navigation attempts only when manual start is enabled and browser is not running |
| 1344 | // Allow auto-initialization for normal operation (e.g., when using BROWSER_RESTART=browser) |
| 1345 | if (!this.isRunning && this.options.manualStart && (!this.browser || !this.browserContext || !this.page)) { |
| 1346 | throw new Error('Cannot navigate: browser is not running or has been closed') |
| 1347 | } |
| 1348 | |
| 1349 | if (!/^\w+\:(\/\/|.+)/.test(url)) { |
| 1350 | url = this.options.url + (!this.options.url.endsWith('/') && url.startsWith('/') ? url : `/${url}`) |
| 1351 | this.debug(`Changed URL to base url + relative path: ${url}`) |
| 1352 | } |
| 1353 | |
| 1354 | if (this.options.basicAuth && this.isAuthenticated !== true) { |
| 1355 | if (url.includes(this.options.url)) { |
| 1356 | await this.browserContext.setHTTPCredentials(this.options.basicAuth) |
| 1357 | this.isAuthenticated = true |
| 1358 | } |
| 1359 | } |
| 1360 | |
| 1361 | // Ensure browser is initialized before page operations |
| 1362 | if (!this.page) { |
| 1363 | this.debugSection('Auto-initializing', `Browser not started properly. page=${!!this.page}, isRunning=${this.isRunning}, browser=${!!this.browser}, browserContext=${!!this.browserContext}`) |
| 1364 | |
| 1365 | if (!this.browser) { |
| 1366 | await this._startBrowser() |
| 1367 | } |
| 1368 | |
| 1369 | // Create browser context and page (simplified version of _before logic) |
| 1370 | if (!this.browserContext) { |
| 1371 | if (!this.browser) { |
| 1372 | throw new Error('Browser is not available for context creation. Browser may have been closed.') |
| 1373 | } |
| 1374 | const contextOptions = { |
| 1375 | ignoreHTTPSErrors: this.options.ignoreHTTPSErrors, |
| 1376 | acceptDownloads: true, |
| 1377 | ...this.options.emulate, |
| 1378 | } |
| 1379 | |
| 1380 | try { |
| 1381 | this.browserContext = await this.browser.newContext(contextOptions) |
| 1382 | } catch (err) { |
| 1383 | // In worker mode with Playwright 1.x, there's a known issue where newContext() fails |
| 1384 | // with "selector engine already registered" when selectors are registered globally |
| 1385 | // across worker threads. This is safe to retry without ANY custom options. |
| 1386 | if (err.message && err.message.includes('already registered')) { |
| 1387 | this.debugSection('Worker Mode', 'Selector conflict in amOnPage, retrying with empty options') |
| 1388 | // Create context with NO options to avoid selector conflicts |
| 1389 | this.browserContext = await this.browser.newContext() |
| 1390 | } else { |
| 1391 | throw err |
| 1392 | } |
| 1393 | } |
| 1394 | } |
| 1395 |
nothing calls this directly
no test coverage detected