Skip to content

Commit

Permalink
Merge branch 'master' into fix/cookie-value-support-contain-=
Browse files Browse the repository at this point in the history
  • Loading branch information
capricorn86 authored Nov 6, 2024
2 parents b3406fa + f5e1722 commit b545943
Show file tree
Hide file tree
Showing 41 changed files with 817 additions and 201 deletions.
12 changes: 12 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Security Policy

## Supported Versions

| Version | Supported |
| --------- | ------------------ |
| > 15.10.0 | :white_check_mark: |
| < 15.10.0 | :x: |

## Reporting a Vulnerability

Use the [Github Vulnaribilty Reporter](https://github.com/capricorn86/happy-dom/security) tool to report your findings.
133 changes: 60 additions & 73 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions packages/global-registrator/src/GlobalRegistrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class GlobalRegistrator {
throw new Error('Failed to register. Happy DOM has already been globally registered.');
}

const window = new GlobalWindow({ ...options, console: global.console });
const window = new GlobalWindow({ ...options, console: globalThis.console });

this.registered = {};

Expand All @@ -38,7 +38,7 @@ export default class GlobalRegistrator {
for (const key of Object.keys(propertyDescriptors)) {
if (!IGNORE_LIST.includes(key)) {
const windowPropertyDescriptor = propertyDescriptors[key];
const globalPropertyDescriptor = Object.getOwnPropertyDescriptor(global, key);
const globalPropertyDescriptor = Object.getOwnPropertyDescriptor(globalThis, key);

if (
globalPropertyDescriptor?.value === undefined ||
Expand All @@ -48,11 +48,11 @@ export default class GlobalRegistrator {

// If the property is the window object, replace it with the global object
if (windowPropertyDescriptor.value === window) {
window[key] = global;
windowPropertyDescriptor.value = global;
window[key] = globalThis;
windowPropertyDescriptor.value = globalThis;
}

Object.defineProperty(global, key, {
Object.defineProperty(globalThis, key, {
...windowPropertyDescriptor,
configurable: true
});
Expand All @@ -69,18 +69,18 @@ export default class GlobalRegistrator {

// If the property is the window object, replace it with the global object
if (propertyDescriptor.value === window) {
window[key] = global;
propertyDescriptor.value = global;
window[key] = globalThis;
propertyDescriptor.value = globalThis;
}

Object.defineProperty(global, key, {
Object.defineProperty(globalThis, key, {
...propertyDescriptor,
configurable: true
});
}

// Set owner window on document to global
global.document[PropertySymbol.defaultView] = global;
globalThis.document[PropertySymbol.defaultView] = globalThis;
}

/**
Expand All @@ -93,13 +93,13 @@ export default class GlobalRegistrator {
);
}

const happyDOM = global.happyDOM;
const happyDOM = globalThis.happyDOM;

for (const key of Object.keys(this.registered)) {
if (this.registered[key] !== null) {
Object.defineProperty(global, key, this.registered[key]);
Object.defineProperty(globalThis, key, this.registered[key]);
} else {
delete global[key];
delete globalThis[key];
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/happy-dom/src/browser/BrowserSettingsFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export default class BrowserSettingsFactory {
...DefaultBrowserSettings.timer,
...settings?.timer
},
fetch: {
...DefaultBrowserSettings.fetch,
...settings?.fetch
},
device: {
...DefaultBrowserSettings.device,
...settings?.device
Expand Down
3 changes: 3 additions & 0 deletions packages/happy-dom/src/browser/DefaultBrowserSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export default <IBrowserSettings>{
maxIntervalIterations: -1,
preventTimerLoops: false
},
fetch: {
disableSameOriginPolicy: false
},
navigation: {
disableMainFrameNavigation: false,
disableChildFrameNavigation: false,
Expand Down
16 changes: 15 additions & 1 deletion packages/happy-dom/src/browser/types/IBrowserSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,28 @@ export default interface IBrowserSettings {
/** Handle disabled resource loading as success */
handleDisabledFileLoadingAsSuccess: boolean;

/** Settings for timers */
/**
* Settings for timers
*/
timer: {
maxTimeout: number;
maxIntervalTime: number;
maxIntervalIterations: number;
preventTimerLoops: boolean;
};

/**
* Settings for fetch
*/
fetch: {
/**
* Disables same-origin policy (CORS)
*
* @see https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy
*/
disableSameOriginPolicy: boolean;
};

/**
* Disables error capturing.
*
Expand Down
12 changes: 12 additions & 0 deletions packages/happy-dom/src/browser/types/IOptionalBrowserSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ export default interface IOptionalBrowserSettings {
maxIntervalIterations?: number;
};

/**
* Settings for fetch
*/
fetch?: {
/**
* Disables same-origin policy (CORS)
*
* @see https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy
*/
disableSameOriginPolicy?: boolean;
};

/**
* Disables error capturing.
*
Expand Down
7 changes: 5 additions & 2 deletions packages/happy-dom/src/clipboard/ClipboardItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ export default class ClipboardItem {
* @param type Type.
* @returns Data.
*/
public async getType(type: string): Promise<Blob | string> {
public async getType(type: string): Promise<Blob> {
if (!this.#data[type]) {
throw new DOMException(
`Failed to execute 'getType' on 'ClipboardItem': The type '${type}' was not found`
);
}
return this.#data[type];
if (this.#data[type] instanceof Blob) {
return this.#data[type];
}
return new Blob([await this.#data[type]], { type });
}
}
Loading

0 comments on commit b545943

Please sign in to comment.