Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix: strip off hash from request urls (#297)

Yury Semikhatskyda051a72a8a2
diff --git a/src/network.ts b/src/network.ts
index a3979baf7f..fb9ebd3a55 100644
--- a/src/network.ts
+++ b/src/network.ts
@@ -67,6 +67,15 @@ export function rewriteCookies(cookies: SetNetworkCookieParam[]): SetNetworkCook
});
}
+function stripFragmentFromUrl(url: string): string
+{
+ if (!url.indexOf('#'))
+ return url;
+ const parsed = new URL(url);
+ parsed.hash = '';
+ return parsed.href;
+}
+
export type Headers = { [key: string]: string };
export class Request {
@@ -94,7 +103,7 @@ export class Request {
for (const request of redirectChain)
request._finalRequest = this;
this._documentId = documentId;
- this._url = url;
+ this._url = stripFragmentFromUrl(url);
this._resourceType = resourceType;
this._method = method;
this._postData = postData;
diff --git a/test/navigation.spec.js b/test/navigation.spec.js
index fdf6a00e90..f757951fa4 100644
--- a/test/navigation.spec.js
+++ b/test/navigation.spec.js
@@ -390,7 +390,7 @@ module.exports.addTests = function({testRunner, expect, playwright, FFOX, CHROME
expect(requests.length).toBe(1);
expect(requests[0].url()).toBe(dataURL);
});
- it.skip(FFOX || WEBKIT)('should navigate to URL with hash and fire requests without hash', async({page, server}) => {
+ it('should navigate to URL with hash and fire requests without hash', async({page, server}) => {
const requests = [];
page.on('request', request => !utils.isFavicon(request) && requests.push(request));
const response = await page.goto(server.EMPTY_PAGE + '#hash');