Skip to content

Commit

Permalink
fix: [capricorn86#1621] Allow for an URL to be a string or an URL obj…
Browse files Browse the repository at this point in the history
…ect in History.pushState() and History.replaceState() APIs
  • Loading branch information
Sohail Alam committed Nov 23, 2024
1 parent 7914b54 commit 7d630a3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/happy-dom/src/browser/utilities/BrowserFrameURL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export default class BrowserFrameURL {
* @param url URL.
* @returns Relative URL.
*/
public static getRelativeURL(frame: IBrowserFrame, url: string): URL {
url = url || 'about:blank';
public static getRelativeURL(frame: IBrowserFrame, url: string | URL): URL {
url = (url instanceof URL ? url.toString() : url) || 'about:blank';

if (url.startsWith('about:') || url.startsWith('javascript:')) {
return new URL(url);
Expand Down
8 changes: 4 additions & 4 deletions packages/happy-dom/src/history/History.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default class History {
* @param title Title.
* @param [url] URL.
*/
public pushState(state: object, title, url?: string): void {
public pushState(state: object, title, url?: string | URL): void {
if (this.#window.closed) {
return;
}
Expand All @@ -135,7 +135,7 @@ export default class History {

if (url && newURL.origin !== location.origin) {
throw new this.#window.DOMException(
`Failed to execute 'pushState' on 'History': A history state object with URL '${url}' cannot be created in a document with origin '${location.origin}' and URL '${location.href}'.`,
`Failed to execute 'pushState' on 'History': A history state object with URL '${url.toString()}' cannot be created in a document with origin '${location.origin}' and URL '${location.href}'.`,
DOMExceptionNameEnum.securityError
);
}
Expand Down Expand Up @@ -177,7 +177,7 @@ export default class History {
* @param title Title.
* @param [url] URL.
*/
public replaceState(state: object, title, url?: string): void {
public replaceState(state: object, title, url?: string | URL): void {
if (this.#window.closed) {
return;
}
Expand All @@ -193,7 +193,7 @@ export default class History {

if (url && newURL.origin !== location.origin) {
throw new this.#window.DOMException(
`Failed to execute 'pushState' on 'History': A history state object with URL '${url}' cannot be created in a document with origin '${location.origin}' and URL '${location.href}'.`,
`Failed to execute 'pushState' on 'History': A history state object with URL '${url.toString()}' cannot be created in a document with origin '${location.origin}' and URL '${location.href}'.`,
DOMExceptionNameEnum.securityError
);
}
Expand Down

0 comments on commit 7d630a3

Please sign in to comment.