webdriverio icon indicating copy to clipboard operation
webdriverio copied to clipboard

[🐛 Bug]: Opening a new tab crashes webdriver

Open alechirsch opened this issue 8 months ago • 2 comments

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

latest

Node.js Version

latest

Mode

Standalone Mode

Which capabilities are you using?

{
        browserName: 'chrome',
        'goog:chromeOptions': {
            args: process.env.CI ? ['headless', 'disable-gpu'] : []
        }
    }

What happened?

When clicking on a button on a page that opens a new tab, webdriver crashes with the following error message:

What is your expected behavior?

Webdriver should not crash.

How to reproduce the bug.

import { remote } from 'webdriverio'

const browser = await remote({
    capabilities: {
        browserName: 'chrome',
        'goog:chromeOptions': {
            args: process.env.CI ? ['headless', 'disable-gpu'] : []
        }
    }
})

await browser.url('https://pestpatrol1.com/pay-now/');
let allTabs = await browser.getWindowHandles();
let currentTab = allTabs[0]
await browser.$('#custrefid').setValue('123');
await browser.$('#Submit').click();

// NOTE: Everything below can be commented out and it still crashes, this is for the positive case
// When the the number of tabs change, try to change tabs
let newTabs = await browser.getWindowHandles();

if (newTabs.length !== allTabs.length) {
    let newTab = newTabs.find(tab => tab !== currentTab);
    await browser.switchToWindow(newTab);
}

await new Promise(resolve => setTimeout(resolve, 5000));

await browser.$('#btncancel1').click();

Note that the following does work, this seems to only be an issue for standalone:

import { expect, browser } from '@wdio/globals'

describe('My Login application', () => {
    it('should login with valid credentials', async () => {
        await browser.url('https://pestpatrol1.com/pay-now/');
        let allTabs = await browser.getWindowHandles();
        let currentTab = allTabs[0]
        await browser.$('#custrefid').setValue('123');
        await browser.$('#Submit').click();
        

        // When the the number of tabs change, try to change tabs
        let newTabs = await browser.getWindowHandles();
        console.log(allTabs);
        
        if (newTabs.length !== allTabs.length) {
            let newTab = newTabs.find(tab => tab !== currentTab);
            await browser.switchToWindow(newTab);
        }

        await new Promise(resolve => setTimeout(resolve, 5000));

      await browser.$('#btncancel1').click();
    })
})

Relevant log output

2025-03-26T23:12:02.472Z INFO webdriver: Initiate new session using the WebDriver protocol
2025-03-26T23:12:02.623Z INFO webdriver: Using Chromedriver v134.0.6998.166 from cache directory /var/folders/g_/8bjqys8d57b2pw2xs91fxl5m0000gp/T
2025-03-26T23:12:02.633Z INFO chromedriver: Starting ChromeDriver 134.0.6998.166 (0b26d3a1ee1e44572492002c2e52ffcd13ac701b-refs/branch-heads/6998@{#2123}) on port 52454
2025-03-26T23:12:02.633Z INFO chromedriver: Remote connections are allowed by an allowlist (0.0.0.0).
2025-03-26T23:12:02.633Z INFO chromedriver: Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
2025-03-26T23:12:02.634Z INFO chromedriver: ChromeDriver was started successfully on port 52454.
2025-03-26T23:12:03.632Z INFO @wdio/utils: Started Chromedriver v134.0.6998.166 with params --port=52454 --allowed-origins=* --allowed-ips=0.0.0.0 in 1100ms on port 52454
2025-03-26T23:12:03.635Z INFO webdriver: [POST] http://localhost:52454/session
2025-03-26T23:12:03.635Z INFO webdriver: DATA {
  capabilities: {
    alwaysMatch: {
      browserName: 'chrome',
      'goog:chromeOptions': [Object],
      webSocketUrl: true,
      unhandledPromptBehavior: 'ignore'
    },
    firstMatch: [ {} ]
  }
}
2025-03-26T23:12:04.226Z INFO webdriver: Register BiDi handler for session with id c63499cfcd29d4c286f0d64bde64c51c
2025-03-26T23:12:04.226Z INFO webdriver: Connecting to webSocketUrl ws://127.0.0.1:52454/session/c63499cfcd29d4c286f0d64bde64c51c
2025-03-26T23:12:04.230Z INFO webdriver: Connected to Bidi protocol at ws://127.0.0.1:52454/session/c63499cfcd29d4c286f0d64bde64c51c
2025-03-26T23:12:04.230Z INFO webdriver: Connected to WebDriver Bidi interface at ws://127.0.0.1:52454/session/c63499cfcd29d4c286f0d64bde64c51c
2025-03-26T23:12:04.231Z INFO webdriver: BIDI COMMAND browsingContext.getTree {}
2025-03-26T23:12:04.231Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["browsingContext.contextCreated"]}
2025-03-26T23:12:04.231Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["log.entryAdded","browsingContext.navigationStarted"]}
2025-03-26T23:12:04.231Z INFO webdriver: BIDI COMMAND script.addPreloadScript { functionDeclaration: <PreloadScript[1319 bytes]>, contexts: undefined }
2025-03-26T23:12:04.231Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["browsingContext.navigationStarted","browsingContext.fragmentNavigated","network.responseCompleted","network.beforeRequestSent","network.fetchError"]}
2025-03-26T23:12:04.231Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["browsingContext.userPromptOpened"]}
2025-03-26T23:12:04.231Z INFO webdriver: BIDI COMMAND session.subscribe {"events":["browsingContext.navigationStarted"]}
2025-03-26T23:12:04.232Z INFO webdriver: COMMAND getWindowHandle()
2025-03-26T23:12:04.232Z INFO webdriver: [GET] http://localhost:52454/session/c63499cfcd29d4c286f0d64bde64c51c/window
2025-03-26T23:12:04.233Z INFO webdriver: RESULT C4ACBD240614E9524B97B1A10FE2C7C2
2025-03-26T23:12:04.234Z INFO webdriver: BIDI RESULT {"id":1,"result":{"contexts":[{"children":[],"clientWindow":"","context":"C4ACBD240614E9524B97B1A10FE2C7C2","originalOpener":null,"parent":null,"url":"about:blank","userContext":"default"}]},"type":"success"}
2025-03-26T23:12:04.234Z INFO webdriverio:PolyfillManager: Adding polyfill script to context with id C4ACBD240614E9524B97B1A10FE2C7C2
2025-03-26T23:12:04.234Z INFO webdriver: BIDI COMMAND script.addPreloadScript { functionDeclaration: <PreloadScript[442 bytes]>, contexts: ["C4ACBD240614E9524B97B1A10FE2C7C2"] }
2025-03-26T23:12:04.234Z INFO webdriver: BIDI COMMAND script.callFunction {"functionDeclaration":"<Function[442 bytes] webdriverioPolyfill>","target":{"children":[],"clientWindow":"","context":"C4ACBD240614E9524B97B1A10FE2C7C2","originalOpener":null,"parent":null,"url":"about:blank","userContext":"default"},"awaitPromise":false}
2025-03-26T23:12:04.235Z INFO webdriver: BIDI RESULT {"id":2,"result":{"subscription":"dfab98da-f0d4-4107-901d-5319354f26a0"},"type":"success"}
2025-03-26T23:12:04.236Z INFO webdriver: BIDI RESULT {"id":3,"result":{"subscription":"d4895911-52b2-42c0-ab51-5ed9e9a2363f"},"type":"success"}
2025-03-26T23:12:04.236Z INFO webdriver: BIDI RESULT {"id":5,"result":{"subscription":"c5f27717-df58-45a7-98fc-8a19bd667b6c"},"type":"success"}
2025-03-26T23:12:04.237Z INFO webdriver: BIDI RESULT {"id":6,"result":{"subscription":"716d9121-fbe6-4cb2-8085-db91b3c5c90e"},"type":"success"}
2025-03-26T23:12:04.237Z INFO webdriver: BIDI RESULT {"id":7,"result":{"subscription":"5b0667c8-f0ab-4fc9-a935-097eb1a162ab"},"type":"success"}
2025-03-26T23:12:04.237Z INFO webdriver: BIDI RESULT {"id":4,"result":{"script":"253ce926-9add-46bd-ae42-81c2c0f4acd8"},"type":"success"}
2025-03-26T23:12:04.237Z INFO webdriver: BIDI RESULT {"id":8,"result":{"script":"7791a686-75bb-45c8-8e22-d82c71460e23"},"type":"success"}
2025-03-26T23:12:04.238Z INFO webdriver: BIDI RESULT {"id":9,"result":{"realm":"990482507606306629.-2900255483271870153","result":{"type":"undefined"},"type":"success"},"type":"success"}
2025-03-26T23:12:04.238Z INFO webdriver: BIDI COMMAND browsingContext.navigate {"context":"C4ACBD240614E9524B97B1A10FE2C7C2","url":"https://pestpatrol1.com/pay-now/","wait":"complete"}
2025-03-26T23:12:06.162Z INFO webdriver: BIDI RESULT {"id":10,"result":{"navigation":"df2b88a7-31e5-4370-bd2d-161e2e060cdd","url":"https://pestpatrol1.com/pay-now/"},"type":"success"}
2025-03-26T23:12:06.163Z INFO webdriver: COMMAND getWindowHandles()
2025-03-26T23:12:06.163Z INFO webdriver: [GET] http://localhost:52454/session/c63499cfcd29d4c286f0d64bde64c51c/window/handles
2025-03-26T23:12:06.165Z INFO webdriver: RESULT [ 'C4ACBD240614E9524B97B1A10FE2C7C2' ]
2025-03-26T23:12:06.167Z INFO webdriver: BIDI COMMAND browsingContext.locateNodes {"locator":{"type":"css","value":"#custrefid"},"context":"C4ACBD240614E9524B97B1A10FE2C7C2"}
2025-03-26T23:12:06.170Z INFO webdriver: BIDI RESULT {"id":11,"result":{"nodes":[{"sharedId":"f.C4ACBD240614E9524B97B1A10FE2C7C2.d.CE9B46137BFDA880287DEC9BF9BBF76E.e.34","type":"node","value":{"attributes":{"id":"custrefid","name":"custrefid","required":"","type":"text","value":""},"childNodeCount":0,"localName":"input","namespaceURI":"http://www.w3.org/1999/xhtml","nodeType":1,"shadowRoot":{"sharedId":"f.C4ACBD240614E9524B97B1A10FE2C7C2.d.CE9B46137BFDA880287DEC9BF9BBF76E.e.48","type":"node","value":{"childNodeCount":1,"mode":"closed","nodeType":11}}}}]},"type":"success"}
2025-03-26T23:12:06.174Z INFO webdriver: COMMAND elementClear("f.C4ACBD240614E9524B97B1A10FE2C7C2.d.CE9B46137BFDA880287DEC9BF9BBF76E.e.34")
2025-03-26T23:12:06.174Z INFO webdriver: [POST] http://localhost:52454/session/c63499cfcd29d4c286f0d64bde64c51c/element/f.C4ACBD240614E9524B97B1A10FE2C7C2.d.CE9B46137BFDA880287DEC9BF9BBF76E.e.34/clear
2025-03-26T23:12:06.191Z INFO webdriver: RESULT null
2025-03-26T23:12:06.192Z INFO webdriver: COMMAND elementSendKeys("f.C4ACBD240614E9524B97B1A10FE2C7C2.d.CE9B46137BFDA880287DEC9BF9BBF76E.e.34", "123")
2025-03-26T23:12:06.192Z INFO webdriver: [POST] http://localhost:52454/session/c63499cfcd29d4c286f0d64bde64c51c/element/f.C4ACBD240614E9524B97B1A10FE2C7C2.d.CE9B46137BFDA880287DEC9BF9BBF76E.e.34/value
2025-03-26T23:12:06.192Z INFO webdriver: DATA { text: '123' }
2025-03-26T23:12:06.249Z INFO webdriver: RESULT null
2025-03-26T23:12:06.249Z INFO webdriver: BIDI COMMAND browsingContext.locateNodes {"locator":{"type":"css","value":"#Submit"},"context":"C4ACBD240614E9524B97B1A10FE2C7C2"}
2025-03-26T23:12:06.251Z INFO webdriver: BIDI RESULT {"id":12,"result":{"nodes":[{"sharedId":"f.C4ACBD240614E9524B97B1A10FE2C7C2.d.CE9B46137BFDA880287DEC9BF9BBF76E.e.50","type":"node","value":{"attributes":{"id":"Submit","name":"Submit","type":"Submit","value":"Pay Now"},"childNodeCount":0,"localName":"input","namespaceURI":"http://www.w3.org/1999/xhtml","nodeType":1,"shadowRoot":{"sharedId":"f.C4ACBD240614E9524B97B1A10FE2C7C2.d.CE9B46137BFDA880287DEC9BF9BBF76E.e.51","type":"node","value":{"childNodeCount":1,"mode":"closed","nodeType":11}}}}]},"type":"success"}
2025-03-26T23:12:06.252Z INFO webdriver: COMMAND elementClick("f.C4ACBD240614E9524B97B1A10FE2C7C2.d.CE9B46137BFDA880287DEC9BF9BBF76E.e.50")
2025-03-26T23:12:06.252Z INFO webdriver: [POST] http://localhost:52454/session/c63499cfcd29d4c286f0d64bde64c51c/element/f.C4ACBD240614E9524B97B1A10FE2C7C2.d.CE9B46137BFDA880287DEC9BF9BBF76E.e.50/click
2025-03-26T23:12:06.284Z INFO webdriver: RESULT null
2025-03-26T23:12:06.284Z INFO webdriver: COMMAND getWindowHandles()
2025-03-26T23:12:06.284Z INFO webdriver: [GET] http://localhost:52454/session/c63499cfcd29d4c286f0d64bde64c51c/window/handles
2025-03-26T23:12:07.072Z INFO webdriverio:PolyfillManager: Adding polyfill script to context with id FD12DB91BE86F1B509613A557E4F0690
2025-03-26T23:12:07.072Z INFO webdriver: BIDI COMMAND script.addPreloadScript { functionDeclaration: <PreloadScript[442 bytes]>, contexts: ["FD12DB91BE86F1B509613A557E4F0690"] }
2025-03-26T23:12:07.072Z INFO webdriver: BIDI COMMAND script.callFunction {"functionDeclaration":"<Function[442 bytes] webdriverioPolyfill>","target":{"children":null,"clientWindow":"","context":"FD12DB91BE86F1B509613A557E4F0690","originalOpener":"C4ACBD240614E9524B97B1A10FE2C7C2","parent":null,"url":"about:blank","userContext":"default"},"awaitPromise":false}
2025-03-26T23:12:07.073Z INFO webdriver: RESULT [
  'C4ACBD240614E9524B97B1A10FE2C7C2',
  'FD12DB91BE86F1B509613A557E4F0690'
]
[ 'C4ACBD240614E9524B97B1A10FE2C7C2' ]
2025-03-26T23:12:07.074Z INFO webdriver: COMMAND switchToWindow("<Screenshot[base64]>")
2025-03-26T23:12:07.074Z INFO webdriver: [POST] http://localhost:52454/session/c63499cfcd29d4c286f0d64bde64c51c/window
2025-03-26T23:12:07.074Z INFO webdriver: DATA { handle: 'FD12DB91BE86F1B509613A557E4F0690' }
2025-03-26T23:12:07.081Z INFO webdriver: RESULT null
2025-03-26T23:12:07.086Z INFO webdriver: BIDI RESULT {"id":13,"result":{"script":"0cd35aa1-44ea-4e13-a970-5c977e5d69da"},"type":"success"}
2025-03-26T23:12:07.086Z INFO webdriver: BIDI RESULT {"id":14,"result":{"realm":"-8093778767850116313.7995754667242821924","result":{"type":"undefined"},"type":"success"},"type":"success"}
2025-03-26T23:12:07.870Z INFO webdriverio:PolyfillManager: Adding polyfill script to context with id 0D888D163B521DA053E632A9B98D7999
2025-03-26T23:12:07.870Z INFO webdriver: BIDI COMMAND script.addPreloadScript { functionDeclaration: <PreloadScript[442 bytes]>, contexts: ["0D888D163B521DA053E632A9B98D7999"] }
2025-03-26T23:12:07.870Z INFO webdriver: BIDI COMMAND script.callFunction {"functionDeclaration":"<Function[442 bytes] webdriverioPolyfill>","target":{"children":null,"clientWindow":"","context":"0D888D163B521DA053E632A9B98D7999","originalOpener":"FD12DB91BE86F1B509613A557E4F0690","parent":null,"url":"about:blank","userContext":"default"},"awaitPromise":false}
2025-03-26T23:12:07.904Z INFO webdriver: BIDI RESULT {"error":"no such frame","id":15,"message":"Context 0D888D163B521DA053E632A9B98D7999 not found","type":"error"}
file:///Users/xxxx/Documents/projects/wdio-test/node_modules/webdriver/build/node.js:472
    const failError = new Error(`WebDriver Bidi command "${params.method}" failed`);
                      ^

Error: WebDriver Bidi command "script.addPreloadScript" failed with error: no such frame - Context 0D888D163B521DA053E632A9B98D7999 not found
    at BidiHandler.send (file:///Users/xxxx/Documents/projects/wdio-test/node_modules/webdriver/build/node.js:472:23)
    at BidiHandler.scriptAddPreloadScript (file:///Users/xxxx/Documents/projects/wdio-test/node_modules/webdriver/build/node.js:912:31)
    at Browser.value (file:///Users/xxxx/Documents/projects/wdio-test/node_modules/webdriver/build/node.js:1298:26)
    at Browser.wrapCommandFn (file:///Users/xxxx/Documents/projects/wdio-test/node_modules/@wdio/utils/build/index.js:902:32)
    at Browser.<anonymous> (file:///Users/xxxx/Documents/projects/wdio-test/node_modules/@wdio/utils/build/index.js:1017:20)
    at #registerScripts (file:///Users/xxxx/Documents/projects/wdio-test/node_modules/webdriverio/build/node.js:3578:39)
    at EventEmitter.emit (node:events:524:28)
    at EventEmitter.emit (node:domain:489:12)
    at WebDriver.prototype.<computed> [as emit] (file:///Users/xxxx/Documents/projects/wdio-test/node_modules/@wdio/utils/build/index.js:462:29)
    at Browser.parseBidiMessage (file:///Users/xxxx/Documents/projects/wdio-test/node_modules/webdriver/build/node.js:1311:10)

Code of Conduct

  • [x] I agree to follow this project's Code of Conduct

Is there an existing issue for this?

  • [x] I have searched the existing issues

alechirsch avatar Mar 26 '25 23:03 alechirsch

Thanks for reporting!

We greatly appreciate any contributions that help resolve the bug. While we understand that active contributors have their own priorities, we kindly request your assistance if you rely on this bug being fixed. We encourage you to take a look at our contribution guidelines or join our friendly Discord development server, where you can ask any questions you may have. Thank you for your support, and cheers!

wdio-bot avatar Mar 27 '25 09:03 wdio-bot

Hello, I'm experiencing this exact same issue.

JordiSAGE avatar Apr 04 '25 11:04 JordiSAGE