Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [#1669] Adds null check for if browser frame isnt available in Response during tear down of the Browser #1673

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading