fix: cross-origin Page.goto referer (#27859)

Fixes https://github.com/microsoft/playwright/issues/27765
This commit is contained in:
Max Schmitt 2023-10-31 11:10:15 +01:00 committed by GitHub
parent 08685a654a
commit cff9ac04e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -587,7 +587,7 @@ class FrameSession {
}
async _navigate(frame: frames.Frame, url: string, referrer: string | undefined): Promise<frames.GotoResult> {
const response = await this._client.send('Page.navigate', { url, referrer, frameId: frame._id });
const response = await this._client.send('Page.navigate', { url, referrer, frameId: frame._id, referrerPolicy: 'unsafeUrl' });
if (response.errorText)
throw new frames.NavigationAbortedError(response.loaderId, `${response.errorText} at ${url}`);
return { newDocumentId: response.loaderId };

View File

@ -632,6 +632,21 @@ it('should send referer', async ({ page, server }) => {
expect(page.url()).toBe(server.PREFIX + '/grid.html');
});
it('should send referer of cross-origin URL', async ({ page, server }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/27765' });
const [request1, request2] = await Promise.all([
server.waitForRequest('/grid.html'),
server.waitForRequest('/digits/1.png'),
page.goto(server.PREFIX + '/grid.html', {
referer: 'https://microsoft.com/xbox/'
}),
]);
expect(request1.headers['referer']).toBe('https://microsoft.com/xbox/');
// Make sure subresources do not inherit referer.
expect(request2.headers['referer']).toBe(server.PREFIX + '/grid.html');
expect(page.url()).toBe(server.PREFIX + '/grid.html');
});
it('should reject referer option when setExtraHTTPHeaders provides referer', async ({ page, server }) => {
await page.setExtraHTTPHeaders({ 'referer': 'http://microsoft.com/' });
let error;