Skip to content

Commit

Permalink
fix: [#1669] Adds null check for if browser frame isnt available in R…
Browse files Browse the repository at this point in the history
…esponse during tear down of the Browser
  • Loading branch information
capricorn86 committed Jan 7, 2025
1 parent 4732136 commit 7eee3a4
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions packages/happy-dom/src/fetch/Response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ export default class Response implements Response {
}

const browserFrame = new WindowBrowserContext(window).getBrowserFrame();

// No browser frame means that the browser is being teared down.
if (!browserFrame) {
return new ArrayBuffer(0);
}

const asyncTaskManager = browserFrame[PropertySymbol.asyncTaskManager];

(<boolean>this.bodyUsed) = true;
Expand Down Expand Up @@ -161,6 +167,12 @@ export default class Response implements Response {
}

const browserFrame = new WindowBrowserContext(window).getBrowserFrame();

// No browser frame means that the browser is being teared down.
if (!browserFrame) {
return Buffer.alloc(0);
}

const asyncTaskManager = browserFrame[PropertySymbol.asyncTaskManager];

(<boolean>this.bodyUsed) = true;
Expand Down Expand Up @@ -203,6 +215,12 @@ export default class Response implements Response {
}

const browserFrame = new WindowBrowserContext(window).getBrowserFrame();

// No browser frame means that the browser is being teared down.
if (!browserFrame) {
return '';
}

const asyncTaskManager = browserFrame[PropertySymbol.asyncTaskManager];

(<boolean>this.bodyUsed) = true;
Expand Down Expand Up @@ -247,6 +265,12 @@ export default class Response implements Response {
public async formData(): Promise<FormData> {
const window = this[PropertySymbol.window];
const browserFrame = new WindowBrowserContext(window).getBrowserFrame();

// No browser frame means that the browser is being teared down.
if (!browserFrame) {
return new window.FormData();
}

const asyncTaskManager = browserFrame[PropertySymbol.asyncTaskManager];
const contentType = this.headers.get('Content-Type');

Expand Down

0 comments on commit 7eee3a4

Please sign in to comment.