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

Request object does not contain postData for file/blob #230

Closed
derevnjuk opened this issue Mar 7, 2023 · 0 comments · Fixed by #231
Closed

Request object does not contain postData for file/blob #230

derevnjuk opened this issue Mar 7, 2023 · 0 comments · Fixed by #231
Assignees
Labels
Type: bug Something isn't working

Comments

@derevnjuk
Copy link
Member

Stack trace
An output of execution with NODE_DEBUG=cypress-har-generator in the environment:

CYPRESS-HAR-GENERATOR 71195: The plugin receives from the CDP: {"method":"Network.requestWillBeSent","params":{"requestId":"72375.67","loaderId":"01E5D63DAE7FA33CD7871A317421E97E","documentURL":"http://localhost:8080/pages/post-data","request":{"url":"http://localhost:8080/api/echo","method":"POST","headers":{"sec-ch-ua":"","sec-ch-ua-platform":"","Referer":"http://localhost:8080/pages/post-data","sec-ch-ua-mobile":"?0","User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/110.0.5481.177 Safari/537.36","Content-Type":"text/xml"},"hasPostData":true,"mixedContentType":"none","initialPriority":"High","referrerPolicy":"strict-origin-when-cross-origin","isSameSite":true},"timestamp":840585.128002,"wallTime":1678194739.973578,"initiator":{"type":"script","stack":{"callFrames":[{"functionName":"","scriptId":"20","url":"http://localhost:8080/pages/post-data","lineNumber":42,"columnNumber":4}]}},"redirectHasExtraInfo":false,"type":"Fetch","frameId":"0EAF2C6F51B54B385D52DC98E2FB76DB","hasUserGesture":false},"sessionId":"C2847CAF71AE4207E536EB03C654928E"}
CYPRESS-HAR-GENERATOR 71195: The plugin sends to the CDP: {"id":7,"method":"Network.getRequestPostData","params":{"requestId":"72375.67"}}
CYPRESS-HAR-GENERATOR 71195: Session C2847CAF71AE4207E536EB03C654928E associated with request: 72375.67
CYPRESS-HAR-GENERATOR 71195: The plugin receives from the CDP: {"id":7,"error":{"code":-32601,"message":"'Network.getRequestPostData' wasn't found"}}

Steps to reproduce

  1. Modify a mock server defined in Send only necessary commands to retrieve the request post data #228
-app.get('/api/echo', (req: Request, res: Response) => res.json(req.body));
+app.post('/api/echo', raw(), (req: Request, res: Response) => res.text(req.body.toString()));

The index.hbs should be updated accordingly:

  <script>
-    const postData = {
-      document: document.body.innerHTML,
-    };
    const pre = document.querySelector('pre')
+    const blobContent = new XMLSerializer().serializeToString(document);

    fetch('/api/echo', {
      method: 'POST',
-      headers: { 'Content-Type': 'application/json' },
-      body: JSON.stringify(postData)
+      headers: { 'Content-Type': 'text/xml' },
+      body: new Blob([blobContent]) 
    })
-      .then(response => response.json())
-      .then(data => pre.innerText = JSON.stringify(data, null, 2))
+      .then(response => response.text())
+      .then(data => pre.innerText = data)
      .catch(error => console.error(error));
  </script>
  1. Open a page and start recording using the following code:
cy.recordHar({ content: false });

cy.visit('/');

cy.saveHar({ waitForIdle: true });

Expected behavior
The HAR contains a postData for the request and is not affected by the type of BodyInit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: bug Something isn't working
Projects
None yet
1 participant