puppeteer: [Bug]: ProtocolError: Could not load body for this request. This might happen if the request is a preflight request
Bug expectation
Background: I do an ui test
Version: puppeteer: 19.7.5
scene: I test a form, so i fill a form to create a item, then it will change the url automatically with detail. Now, i need to the request’s response for creating. But it catch a error ProtocolError: Could not load body for this request. This might happen if the request is a preflight request
. There is no Cross-domain request.
code: The test case is following.
` javascript
it('create new Page', async () => {
await expect(page).toClick('button>span', {
text: 'create new Page',
});
const { confirm, modal } = await waitForModal(page);
await expect(modal).toFill(
".input-module-content>input[placeholder='please input ']",
// fill a name
WIKI_SPACE_NAME
)
// then click confirm
const [response] = await Promise.all([
page.waitForResponse(WikiInterceptors.wikiSpaceAdd({ teamUUID })),
confirm()
]);
// wait navigation
await page.waitForNavigation();
// parse the reponse but catch a error
const spaceInfo = await response.json();
await expect(spaceInfo).toBeDefined();
spaceUUID = spaceInfo?.uuid;})`
what i try to solve.
- launch with params
launch: { args: [ "--no-sandbox", "--disable-gpu", "--disable-setuid-sandbox", "--disable-background-timer-throttling", "--disable-backgrounding-occluded-windows", "--disable-renderer-backgrounding" ], }
- change the request Interception mode
const [response] = await Promise.all([ page.waitForResponse((response) => response.url().include('xxx'), { waitUntil: "networkidle0", }), confirm() ]);
There are all don’t work out! Help~~~
Bug behavior
- Flaky
Minimal, reproducible example
it("create new Page", async () => {
await expect(page).toClick("button>span", {
text: "create new Page",
});
const { confirm, modal } = await waitForModal(page);
await expect(modal).toFill(
".input-module-content>input[placeholder='please input ']",
// fill a name
WIKI_SPACE_NAME
);
// then click confirm
const [response] = await Promise.all([
page.waitForResponse(WikiInterceptors.wikiSpaceAdd({ teamUUID })),
confirm()
]);
// wait navigation
await page.waitForNavigation();
// parse the reponse but catch a error
const spaceInfo = await response.json()
await expect(spaceInfo).toBeDefined();
spaceUUID = spaceInfo?.uuid;
});
Error string
ProtocolError: Could not load body for this request. This might happen if the request is a preflight request
Puppeteer configuration
No response
Puppeteer version
19.7.5
Node version
v16.14.2
Package manager
pnpm
Package manager version
8.5.0
Operating system
macOS
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 10
- Comments: 25
Workaround
Add this condition in the
waitForResponse
predicate:Nice, just change it to “OPTIONS”.
same problem
Still existing
Same problem
Same, too!
This is not a puppeteer problem, this is a chrome problem. When there is a thread interrupt in the body of a page, the protocol will not return a body. Examples:
<body><script>window.location = 'http://...'</script></body>
or<body><form id="myform">....</form> <script>getElementById('myform').submit()</script></body>
In firefox everything works as it should.
In my case, I solved it this way:
page.on("response", async (response) => {...
In my specific case, the
data.url
already contained what I need, so simply setting this and clicking on it started the download of the required file.Hope that helps someone.
I solved it in my case too, but it was a different circumstance. In my situation I was intercepting the response I was interested in, but the page was redirecting shortly after. Although I had the right response (POST method), getting the body for it was throwing the error.
The way I solved it was to make a GET request to the URL by using
page.goto
, intercept and modify the request method to POST