Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 Bug]: dotnet Execute Script stopped working on few use cases on 4.24 and above #14720

Closed
omer-za opened this issue Nov 6, 2024 · 11 comments

Comments

@omer-za
Copy link

omer-za commented Nov 6, 2024

What happened?

I’m trying to perform a request using JS with the following script.
driver.ExecuteScript(script);
it doesn’t throw any error but also doesn’t perform the request like it was before upgrading selenium version from 4.23 to 4.24

How can we reproduce the issue?

Try to run the following JS on using driver and see if a request is sent.

chrome.webRequest.onHeadersReceived.addListener(
    function(details) {
        var responseHeaders = details.responseHeaders.filter(header => header.name !== 'X-Response-Body-Signature');
        return { responseHeaders };
    },
    {
        urls: ['https://something/vendors/*'],
    },
    ['blocking', 'responseHeaders', 'extraHeaders']
);

function makeRequest (method, url) {
    return new Promise(function (resolve, reject) {
        var xhr = new XMLHttpRequest();
        xhr.open(method, url);
        xhr.addEventListener('load', function () {
            if (xhr.status >= 200 && xhr.status < 300) {
                resolve(xhr.response);
            } else {
                reject({
                    status: xhr.status,
                    statusText: xhr.statusText
                });
            }
        });
        xhr.onerror = function () {
            reject({
                status: xhr.status,
                statusText: xhr.statusText
            });
        };
        xhr.send();
    });
}
makeRequest('GET', 'https://something');


### Relevant log output

```shell
[1730883100.030][INFO]: [86c0407fa12f100431895d5ac7101aa5] COMMAND ExecuteScript {
   "args": [  ],
   "script": "\nchrome.webRequest.onHeadersReceived.addListener(\n    function(details) {\n        var responseHeaders = details.responseHeaders.map(\n            (header) => {\n                if (header.name === 'X-Context-Signature')\n                    header.value = 'bLrAdZ9t6/D/0DnirIq6S452y4OxuUiOFSeQPjsdZn4t3J21TgILC94rXOWsgHNseI91o2vLS007QIKxzQTPfCG046LF191jgysoGPbr2g0LeKacO1RYSCyM8W4SZfSlDfQQIZzT4zb40JiFFtJCltiiWD1arHQjXxgfPGiRAi+5Bwu9fOKS9CVrvNZclrHRinEq2NZctNfCHg4LJIEh/dLdYcXdEe8vdn05a/AqsWBfzeDvQ==';\n                return header;\n        });\n        return { responseHeaders };\n    },\n    {\n        urls: ['https://something'],\n    },\n    ['blocking', 'responseHeaders', 'extraHeaders']\n);\n \nfunction makeRequest (method, url) {\n    return new Promise(function (resolve, reject) {\n        var xhr = new XMLHttpRequest();\n        xhr.open(method, url);\n        xhr.addEventListener('load', function () {\n            if (xhr.status >= 200 && xhr.status \u003C 300) {\n                resolve(xhr.response);\n            } else {\n                reject({\n                    status: xhr.status,\n                    statusText: xhr.statusText\n                });\n            }\n        });\n        xhr.onerror = function () {\n            reject({\n                status: xhr.status,\n                statusText: xhr.statusText\n            });\n        };\n        xhr.send();\n    });\n};\nmakeRequest('GET', 'https://something');\n;"
}
[1730883100.030][INFO]: Waiting for pending navigations...
[1730883100.030][DEBUG]: DevTools WebSocket Command: Runtime.evaluate (id=160) (session_id=2B156A8482D74E7FDB1FFDE9CBAE77BD) 7F3D768072D4CD0BFA0A08FF8A09CA94 {
   "expression": "1"
}
[1730883100.030][DEBUG]: DevTools WebSocket Response: Runtime.evaluate (id=160) (session_id=2B156A8482D74E7FDB1FFDE9CBAE77BD) 7F3D768072D4CD0BFA0A08FF8A09CA94 {
   "result": {
      "description": "1",
      "type": "number",
      "value": 1
   }
}
[1730883100.030][INFO]: Done waiting for pending navigations. Status: ok
[1730883100.030][DEBUG]: DevTools WebSocket Command: Page.getNavigationHistory (id=161) (session_id=2B156A8482D74E7FDB1FFDE9CBAE77BD) 7F3D768072D4CD0BFA0A08FF8A09CA94 {
}
[1730883100.030][DEBUG]: DevTools WebSocket Response: Page.getNavigationHistory (id=161) (session_id=2B156A8482D74E7FDB1FFDE9CBAE77BD) 7F3D768072D4CD0BFA0A08FF8A09CA94 {
   "currentIndex": 0,
   "entries": [ {
      "id": 4,
      "title": "",
      "transitionType": "link",
      "url": "chrome-extension://bdgmpdloimlbdpofeojcfgjdjaelhlcm/_generated_background_page.html",
      "userTypedURL": "chrome-extension://bdgmpdloimlbdpofeojcfgjdjaelhlcm/_generated_background_page.html"
   } ]
}
[1730883100.031][DEBUG]: DevTools WebSocket Command: Runtime.evaluate (id=162) (session_id=2B156A8482D74E7FDB1FFDE9CBAE77BD) 7F3D768072D4CD0BFA0A08FF8A09CA94 {
   "awaitPromise": true,
   "expression": "(function() { // Copyright 2012 The Chromium Authors\n// Use of this source code is governed by a BSD-style license that can be\n// found in the LICENSE file.\n\n/**\n * Enum for WebDriver status codes....",
   "returnByValue": true
}
[1730883100.033][DEBUG]: DevTools WebSocket Response: Runtime.evaluate (id=162) (session_id=2B156A8482D74E7FDB1FFDE9CBAE77BD) 7F3D768072D4CD0BFA0A08FF8A09CA94 {
   "result": {
      "type": "object",
      "value": {
         "status": 0,
         "value": null
      }
   }
}
[1730883100.033][INFO]: Waiting for pending navigations...
[1730883100.033][DEBUG]: DevTools WebSocket Command: Runtime.evaluate (id=163) (session_id=2B156A8482D74E7FDB1FFDE9CBAE77BD) 7F3D768072D4CD0BFA0A08FF8A09CA94 {
   "expression": "1"
}
[1730883100.034][DEBUG]: DevTools WebSocket Response: Runtime.evaluate (id=163) (session_id=2B156A8482D74E7FDB1FFDE9CBAE77BD) 7F3D768072D4CD0BFA0A08FF8A09CA94 {
   "result": {
      "description": "1",
      "type": "number",
      "value": 1
   }
}
[1730883100.034][INFO]: Done waiting for pending navigations. Status: ok
[1730883100.034][INFO]: [86c0407fa12f100431895d5ac7101aa5] RESPONSE ExecuteScript null

Operating System

Mac

Selenium version

4.24

What are the browser(s) and version(s) where you see this issue?

Chrome latest

What are the browser driver(s) and version(s) where you see this issue?

Latest

Are you using Selenium Grid?

No response

Copy link

github-actions bot commented Nov 6, 2024

@omer-za, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@nvborisenko
Copy link
Member

using var driver = new ChromeDriver();
driver.ExecuteScript("console.log('Hi')");

It works to me, am I doing something wrong? @omer-za

@omer-za
Copy link
Author

omer-za commented Nov 11, 2024

@nvborisenko Yes, please use the whole script i've sent above as the provided string.

chrome.webRequest.onHeadersReceived.addListener(
    function(details) {
        var responseHeaders = details.responseHeaders.filter(header => header.name !== 'X-Response-Body-Signature');
        return { responseHeaders };
    },
    {
        urls: ['https://something/vendors/*'],
    },
    ['blocking', 'responseHeaders', 'extraHeaders']
);

function makeRequest (method, url) {
    return new Promise(function (resolve, reject) {
        var xhr = new XMLHttpRequest();
        xhr.open(method, url);
        xhr.addEventListener('load', function () {
            if (xhr.status >= 200 && xhr.status < 300) {
                resolve(xhr.response);
            } else {
                reject({
                    status: xhr.status,
                    statusText: xhr.statusText
                });
            }
        });
        xhr.onerror = function () {
            reject({
                status: xhr.status,
                statusText: xhr.statusText
            });
        };
        xhr.send();
    });
}
makeRequest('GET', 'https://something');

@nvborisenko
Copy link
Member

Unhandled exception. OpenQA.Selenium.JavaScriptException: javascript error: Cannot read properties of undefined (reading 'onHeadersReceived')

Please verify your script manually.

@omer-za
Copy link
Author

omer-za commented Nov 11, 2024

I've set up script variable like this

var script = "\nchrome.webRequest.onHeadersReceived.addListener(\n    function(details) {\n        var responseHeaders = details.responseHeaders.map(\n            (header) => {\n                if (header.name === 'X-Context-Signature')\n                    header.value = 'bLrAdZ9t6/D//z/spDNOo2Dpjg8f/+/dLdYcXdEe8vdn05a/AqsWBfzeDvQ==';\n                return header;\n        });\n        return { responseHeaders };\n    },\n    {\n        urls: ['https://something/*'],\n    },\n    ['blocking', 'responseHeaders', 'extraHeaders']\n);\n \nfunction makeRequest (method, url) {\n    return new Promise(function (resolve, reject) {\n        var xhr = new XMLHttpRequest();\n        xhr.open(method, url);\n        xhr.addEventListener('load', function () {\n            if (xhr.status >= 200 && xhr.status < 300) {\n                resolve(xhr.response);\n            } else {\n                reject({\n                    status: xhr.status,\n                    statusText: xhr.statusText\n                });\n            }\n        });\n        xhr.onerror = function () {\n            reject({\n                status: xhr.status,\n                statusText: xhr.statusText\n            });\n        };\n        xhr.send();\n    });\n}\nmakeRequest('GET', 'https://something');\n;";

@nvborisenko
Copy link
Member

And what is the issue? What exactly doesn't work?

@omer-za
Copy link
Author

omer-za commented Nov 13, 2024

It just doesn't perform the request that it used to before upgrading the library, like that script is not being parsed correctly

@nvborisenko
Copy link
Member

Just to understand whether this issue is really related to the library itself, I have to request you to collect logs https://www.selenium.dev/documentation/webdriver/troubleshooting/logging/:

  • with previous version of the library where the script works
  • with the latest version of the library where the script doesn't work

Then we will be able to compare the diff, thank you.

@omer-za
Copy link
Author

omer-za commented Nov 14, 2024

Seems like there's some escaping issues introduced in 4.24.
The left one is 4.24 which doesn't includes '

@nvborisenko
Copy link
Member

Chatted internally, it is not reproduced on my side.

Copy link

This issue has been automatically locked since there has not been any recent activity since it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants