question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read property '_setRequestBody' of undefined

See original GitHub issue

Current behavior:

Whenever visiting a page in which the XHR id is protected via Object.defineProperties, cypress throws the following error:

Cannot read property '_setRequestBody' of undefined 

The issue here is that the following code in packages/driver/src/cypress/server.js is trying to override the XHR id with a unique id

add (xhr, attrs = {}) {
    const id = _.uniqueId('xhr')

    _.extend(xhr, attrs)
    xhr.id = id
    xhrs[id] = xhr
    proxies[id] = $XHR.create(xhr)

    return proxies[id]
}

But since the id property is immutable in my environment and is referencing the value of another property, like so

Object.defineProperties(XMLHttpRequest.prototype, {
    "id": {
        get: function() {
            return XMLHttpRequest.prototype._id
        }
    }
})

The result is that the code is not being able to locate the proxy for the request, returning undefined instead, thus, causing the error

proxy._setRequestBody(requestBody)

Desired behavior:

I would expect to be able to parameterise the property I want to be considered as an ID, in a way that I would be able to tell cypress to override the property _id instead of id.

Test code to reproduce

Reproduction is available here https://github.com/fltonii/cypress-test-tiny

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:16 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
timostarkcommented, Oct 9, 2020

Hi All, I am experiencing the same issue. The UI library by SAP (Fiori Launchpad based on SAPUI5) is overwriting the XHR Id, which unfortunatly makes it impossible to use cypress for end-to-end UI tests for SAP software. Is there any option to switch to a different attribute name?

See the following code-snipped of the Fiori Launchpad library (as Fiori Launchpad itself is under commercial license i can unfortunatly not provide a running example - but the issue should be pretty clear from the screenshot). grafik

Regards, Timo

2reactions
jennifer-shehanecommented, Jun 26, 2020

This code has been there for quite a while, so I don’t think this was a recently introduced thing.

I can recreate this with the following code:

it("Sample error when XHR id is not available", () => {
  cy.server()
  cy.route("GET", "/api/myService").as("myService");
  cy.visit("https://cy-test-page.uc.r.appspot.com");
  cy.wait("@myService");
  cy.get("#response").should("equal", `{"working":true}`);
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cypress TypeError: Cannot read properties of undefined ...
TypeError : Cannot read properties of undefined (reading 'uid'). Some times it works when I change to a different workspace but again this ......
Read more >
cypress-io/cypress - Gitter
I am currently seeing TypeError: Cannot read property 'target' of undefined when running a spec. I added Cypress.on('fail', (err, runnable) => { debugger...
Read more >
TypeError: Cannot read properties of undefined (reading 'json')
Getting error -> TypeError: Cannot read properties of undefined (reading 'json'). Update: No need to use ".then" since I am using "async ...
Read more >
ConversionError: The undefined value has no properties.
I am getting this error " ConversionError: The undefined value has no properties ." when calling script include from UI action (not client....
Read more >
XMLHttpRequest.send() - Web APIs | MDN
If the request is synchronous, this method doesn't return until the ... the body parameter is ignored and the request body is set...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found