diff --git a/data/worker.mjs b/data/worker.mjs index eabeae4..b05c394 100644 --- a/data/worker.mjs +++ b/data/worker.mjs @@ -1,30 +1,115 @@ +// This file is autogenerated by scripts +// Do NOT modify this file manually + export default { + AbortController: false, + AbortSignal: false, addEventListener: false, applicationCache: false, atob: false, + AudioData: false, + AudioDecoder: false, + AudioEncoder: false, + BackgroundFetchManager: false, + BackgroundFetchRecord: false, + BackgroundFetchRegistration: false, Blob: false, BroadcastChannel: false, btoa: false, ByteLengthQueuingStrategy: false, Cache: false, caches: false, + CacheStorage: false, + cancelAnimationFrame: false, + CanvasGradient: false, + CanvasPattern: false, clearInterval: false, clearTimeout: false, - close: true, + close: false, + CloseEvent: false, CompressionStream: false, console: false, CountQueuingStrategy: false, + createImageBitmap: false, + CropTarget: false, + crossOriginIsolated: false, crypto: false, Crypto: false, CryptoKey: false, + CSSSkewX: false, + CSSSkewY: false, CustomEvent: false, DecompressionStream: false, + DedicatedWorkerGlobalScope: false, + dispatchEvent: false, + DOMException: false, + DOMMatrix: false, + DOMMatrixReadOnly: false, + DOMPoint: false, + DOMPointReadOnly: false, + DOMQuad: false, + DOMRect: false, + DOMRectReadOnly: false, + DOMStringList: false, + EncodedAudioChunk: false, + EncodedVideoChunk: false, ErrorEvent: false, Event: false, + EventSource: false, + EventTarget: false, fetch: false, File: false, + FileList: false, + FileReader: false, FileReaderSync: false, + FileSystemDirectoryHandle: false, + FileSystemFileHandle: false, + FileSystemHandle: false, + FileSystemSyncAccessHandle: false, + FileSystemWritableFileStream: false, + FontFace: false, + fonts: false, FormData: false, + GPU: false, + GPUAdapter: false, + GPUAdapterInfo: false, + GPUBindGroup: false, + GPUBindGroupLayout: false, + GPUBuffer: false, + GPUBufferUsage: false, + GPUCanvasContext: false, + GPUColorWrite: false, + GPUCommandBuffer: false, + GPUCommandEncoder: false, + GPUCompilationInfo: false, + GPUCompilationMessage: false, + GPUComputePassEncoder: false, + GPUComputePipeline: false, + GPUDevice: false, + GPUDeviceLostInfo: false, + GPUError: false, + GPUExternalTexture: false, + GPUInternalError: false, + GPUMapMode: false, + GPUOutOfMemoryError: false, + GPUPipelineError: false, + GPUPipelineLayout: false, + GPUQuerySet: false, + GPUQueue: false, + GPURenderBundle: false, + GPURenderBundleEncoder: false, + GPURenderPassEncoder: false, + GPURenderPipeline: false, + GPUSampler: false, + GPUShaderModule: false, + GPUShaderStage: false, + GPUSupportedFeatures: false, + GPUSupportedLimits: false, + GPUTexture: false, + GPUTextureUsage: false, + GPUTextureView: false, + GPUUncapturedErrorEvent: false, + GPUValidationError: false, Headers: false, IDBCursor: false, IDBCursorWithValue: false, @@ -37,25 +122,45 @@ export default { IDBRequest: false, IDBTransaction: false, IDBVersionChangeEvent: false, + IdleDetector: false, + ImageBitmap: false, + ImageBitmapRenderingContext: false, ImageData: false, - importScripts: true, + ImageDecoder: false, + ImageTrack: false, + ImageTrackList: false, + importScripts: false, indexedDB: false, + isSecureContext: false, location: false, + Lock: false, + LockManager: false, + MediaCapabilities: false, + MediaSource: false, + MediaSourceHandle: false, MessageChannel: false, MessageEvent: false, MessagePort: false, name: false, + NavigationPreloadManager: false, navigator: false, + NavigatorUAData: false, + NetworkInformation: false, Notification: false, + OffscreenCanvas: false, + OffscreenCanvasRenderingContext2D: false, onclose: true, onconnect: true, onerror: true, onlanguagechange: true, onmessage: true, + onmessageerror: true, onoffline: true, ononline: true, onrejectionhandled: true, onunhandledrejection: true, + origin: false, + Path2D: false, performance: false, Performance: false, PerformanceEntry: false, @@ -65,8 +170,18 @@ export default { PerformanceObserver: false, PerformanceObserverEntryList: false, PerformanceResourceTiming: false, + PerformanceServerTiming: false, PerformanceTiming: false, - postMessage: true, + PeriodicSyncManager: false, + Permissions: false, + PermissionStatus: false, + PERSISTENT: false, + postMessage: false, + ProgressEvent: false, + PromiseRejectionEvent: false, + PushManager: false, + PushSubscription: false, + PushSubscriptionOptions: false, queueMicrotask: false, ReadableByteStreamController: false, ReadableStream: false, @@ -76,27 +191,101 @@ export default { ReadableStreamDefaultReader: false, removeEventListener: false, reportError: false, + ReportingObserver: false, Request: false, + requestAnimationFrame: false, Response: false, - self: true, + RTCEncodedAudioFrame: false, + RTCEncodedVideoFrame: false, + scheduler: false, + Scheduler: false, + SecurityPolicyViolationEvent: false, + self: false, + Serial: false, + SerialPort: false, ServiceWorkerRegistration: false, setInterval: false, setTimeout: false, + SourceBuffer: false, + SourceBufferList: false, + StorageManager: false, + structuredClone: false, SubtleCrypto: false, + SyncManager: false, + TaskController: false, + TaskPriorityChangeEvent: false, + TaskSignal: false, + TEMPORARY: false, TextDecoder: false, TextDecoderStream: false, TextEncoder: false, TextEncoderStream: false, + TextMetrics: false, TransformStream: false, TransformStreamDefaultController: false, + TrustedHTML: false, + TrustedScript: false, + TrustedScriptURL: false, + TrustedTypePolicy: false, + TrustedTypePolicyFactory: false, + trustedTypes: false, URL: false, + URLPattern: false, URLSearchParams: false, + USB: false, + USBAlternateInterface: false, + USBConfiguration: false, + USBConnectionEvent: false, + USBDevice: false, + USBEndpoint: false, + USBInterface: false, + USBInTransferResult: false, + USBIsochronousInTransferPacket: false, + USBIsochronousInTransferResult: false, + USBIsochronousOutTransferPacket: false, + USBIsochronousOutTransferResult: false, + USBOutTransferResult: false, + UserActivation: false, + VideoColorSpace: false, + VideoDecoder: false, + VideoEncoder: false, + VideoFrame: false, WebAssembly: false, + WebGL2RenderingContext: false, + WebGLActiveInfo: false, + WebGLBuffer: false, + WebGLContextEvent: false, + WebGLFramebuffer: false, + WebGLProgram: false, + WebGLQuery: false, + WebGLRenderbuffer: false, + WebGLRenderingContext: false, + WebGLSampler: false, + WebGLShader: false, + WebGLShaderPrecisionFormat: false, + WebGLSync: false, + WebGLTexture: false, + WebGLTransformFeedback: false, + WebGLUniformLocation: false, + WebGLVertexArrayObject: false, + webkitRequestFileSystem: false, + webkitRequestFileSystemSync: false, + webkitResolveLocalFileSystemSyncURL: false, + webkitResolveLocalFileSystemURL: false, WebSocket: false, + WebTransport: false, + WebTransportBidirectionalStream: false, + WebTransportDatagramDuplexStream: false, + WebTransportError: false, + WGSLLanguageFeatures: false, Worker: false, WorkerGlobalScope: false, + WorkerLocation: false, + WorkerNavigator: false, WritableStream: false, WritableStreamDefaultController: false, WritableStreamDefaultWriter: false, XMLHttpRequest: false, + XMLHttpRequestEventTarget: false, + XMLHttpRequestUpload: false, }; diff --git a/globals.json b/globals.json index ab0895b..6cf7ab0 100644 --- a/globals.json +++ b/globals.json @@ -1459,32 +1459,114 @@ "XSLTProcessor": false }, "worker": { + "AbortController": false, + "AbortSignal": false, "addEventListener": false, "applicationCache": false, "atob": false, + "AudioData": false, + "AudioDecoder": false, + "AudioEncoder": false, + "BackgroundFetchManager": false, + "BackgroundFetchRecord": false, + "BackgroundFetchRegistration": false, "Blob": false, "BroadcastChannel": false, "btoa": false, "ByteLengthQueuingStrategy": false, "Cache": false, "caches": false, + "CacheStorage": false, + "cancelAnimationFrame": false, + "CanvasGradient": false, + "CanvasPattern": false, "clearInterval": false, "clearTimeout": false, - "close": true, + "close": false, + "CloseEvent": false, "CompressionStream": false, "console": false, "CountQueuingStrategy": false, + "createImageBitmap": false, + "CropTarget": false, + "crossOriginIsolated": false, "crypto": false, "Crypto": false, "CryptoKey": false, + "CSSSkewX": false, + "CSSSkewY": false, "CustomEvent": false, "DecompressionStream": false, + "DedicatedWorkerGlobalScope": false, + "dispatchEvent": false, + "DOMException": false, + "DOMMatrix": false, + "DOMMatrixReadOnly": false, + "DOMPoint": false, + "DOMPointReadOnly": false, + "DOMQuad": false, + "DOMRect": false, + "DOMRectReadOnly": false, + "DOMStringList": false, + "EncodedAudioChunk": false, + "EncodedVideoChunk": false, "ErrorEvent": false, "Event": false, + "EventSource": false, + "EventTarget": false, "fetch": false, "File": false, + "FileList": false, + "FileReader": false, "FileReaderSync": false, + "FileSystemDirectoryHandle": false, + "FileSystemFileHandle": false, + "FileSystemHandle": false, + "FileSystemSyncAccessHandle": false, + "FileSystemWritableFileStream": false, + "FontFace": false, + "fonts": false, "FormData": false, + "GPU": false, + "GPUAdapter": false, + "GPUAdapterInfo": false, + "GPUBindGroup": false, + "GPUBindGroupLayout": false, + "GPUBuffer": false, + "GPUBufferUsage": false, + "GPUCanvasContext": false, + "GPUColorWrite": false, + "GPUCommandBuffer": false, + "GPUCommandEncoder": false, + "GPUCompilationInfo": false, + "GPUCompilationMessage": false, + "GPUComputePassEncoder": false, + "GPUComputePipeline": false, + "GPUDevice": false, + "GPUDeviceLostInfo": false, + "GPUError": false, + "GPUExternalTexture": false, + "GPUInternalError": false, + "GPUMapMode": false, + "GPUOutOfMemoryError": false, + "GPUPipelineError": false, + "GPUPipelineLayout": false, + "GPUQuerySet": false, + "GPUQueue": false, + "GPURenderBundle": false, + "GPURenderBundleEncoder": false, + "GPURenderPassEncoder": false, + "GPURenderPipeline": false, + "GPUSampler": false, + "GPUShaderModule": false, + "GPUShaderStage": false, + "GPUSupportedFeatures": false, + "GPUSupportedLimits": false, + "GPUTexture": false, + "GPUTextureUsage": false, + "GPUTextureView": false, + "GPUUncapturedErrorEvent": false, + "GPUValidationError": false, "Headers": false, "IDBCursor": false, "IDBCursorWithValue": false, @@ -1497,25 +1579,45 @@ "IDBRequest": false, "IDBTransaction": false, "IDBVersionChangeEvent": false, + "IdleDetector": false, + "ImageBitmap": false, + "ImageBitmapRenderingContext": false, "ImageData": false, - "importScripts": true, + "ImageDecoder": false, + "ImageTrack": false, + "ImageTrackList": false, + "importScripts": false, "indexedDB": false, + "isSecureContext": false, "location": false, + "Lock": false, + "LockManager": false, + "MediaCapabilities": false, + "MediaSource": false, + "MediaSourceHandle": false, "MessageChannel": false, "MessageEvent": false, "MessagePort": false, "name": false, + "NavigationPreloadManager": false, "navigator": false, + "NavigatorUAData": false, + "NetworkInformation": false, "Notification": false, + "OffscreenCanvas": false, + "OffscreenCanvasRenderingContext2D": false, "onclose": true, "onconnect": true, "onerror": true, "onlanguagechange": true, "onmessage": true, + "onmessageerror": true, "onoffline": true, "ononline": true, "onrejectionhandled": true, "onunhandledrejection": true, + "origin": false, + "Path2D": false, "performance": false, "Performance": false, "PerformanceEntry": false, @@ -1525,8 +1627,18 @@ "PerformanceObserver": false, "PerformanceObserverEntryList": false, "PerformanceResourceTiming": false, + "PerformanceServerTiming": false, "PerformanceTiming": false, - "postMessage": true, + "PeriodicSyncManager": false, + "Permissions": false, + "PermissionStatus": false, + "PERSISTENT": false, + "postMessage": false, + "ProgressEvent": false, + "PromiseRejectionEvent": false, + "PushManager": false, + "PushSubscription": false, + "PushSubscriptionOptions": false, "queueMicrotask": false, "ReadableByteStreamController": false, "ReadableStream": false, @@ -1536,29 +1648,103 @@ "ReadableStreamDefaultReader": false, "removeEventListener": false, "reportError": false, + "ReportingObserver": false, "Request": false, + "requestAnimationFrame": false, "Response": false, - "self": true, + "RTCEncodedAudioFrame": false, + "RTCEncodedVideoFrame": false, + "scheduler": false, + "Scheduler": false, + "SecurityPolicyViolationEvent": false, + "self": false, + "Serial": false, + "SerialPort": false, "ServiceWorkerRegistration": false, "setInterval": false, "setTimeout": false, + "SourceBuffer": false, + "SourceBufferList": false, + "StorageManager": false, + "structuredClone": false, "SubtleCrypto": false, + "SyncManager": false, + "TaskController": false, + "TaskPriorityChangeEvent": false, + "TaskSignal": false, + "TEMPORARY": false, "TextDecoder": false, "TextDecoderStream": false, "TextEncoder": false, "TextEncoderStream": false, + "TextMetrics": false, "TransformStream": false, "TransformStreamDefaultController": false, + "TrustedHTML": false, + "TrustedScript": false, + "TrustedScriptURL": false, + "TrustedTypePolicy": false, + "TrustedTypePolicyFactory": false, + "trustedTypes": false, "URL": false, + "URLPattern": false, "URLSearchParams": false, + "USB": false, + "USBAlternateInterface": false, + "USBConfiguration": false, + "USBConnectionEvent": false, + "USBDevice": false, + "USBEndpoint": false, + "USBInterface": false, + "USBInTransferResult": false, + "USBIsochronousInTransferPacket": false, + "USBIsochronousInTransferResult": false, + "USBIsochronousOutTransferPacket": false, + "USBIsochronousOutTransferResult": false, + "USBOutTransferResult": false, + "UserActivation": false, + "VideoColorSpace": false, + "VideoDecoder": false, + "VideoEncoder": false, + "VideoFrame": false, "WebAssembly": false, + "WebGL2RenderingContext": false, + "WebGLActiveInfo": false, + "WebGLBuffer": false, + "WebGLContextEvent": false, + "WebGLFramebuffer": false, + "WebGLProgram": false, + "WebGLQuery": false, + "WebGLRenderbuffer": false, + "WebGLRenderingContext": false, + "WebGLSampler": false, + "WebGLShader": false, + "WebGLShaderPrecisionFormat": false, + "WebGLSync": false, + "WebGLTexture": false, + "WebGLTransformFeedback": false, + "WebGLUniformLocation": false, + "WebGLVertexArrayObject": false, + "webkitRequestFileSystem": false, + "webkitRequestFileSystemSync": false, + "webkitResolveLocalFileSystemSyncURL": false, + "webkitResolveLocalFileSystemURL": false, "WebSocket": false, + "WebTransport": false, + "WebTransportBidirectionalStream": false, + "WebTransportDatagramDuplexStream": false, + "WebTransportError": false, + "WGSLLanguageFeatures": false, "Worker": false, "WorkerGlobalScope": false, + "WorkerLocation": false, + "WorkerNavigator": false, "WritableStream": false, "WritableStreamDefaultController": false, "WritableStreamDefaultWriter": false, - "XMLHttpRequest": false + "XMLHttpRequest": false, + "XMLHttpRequestEventTarget": false, + "XMLHttpRequestUpload": false }, "node": { "__dirname": false, diff --git a/package.json b/package.json index 303dfc0..45c3b14 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "update:browser": "node scripts/update.mjs --environment=browser", "update:builtin": "node scripts/update.mjs --environment=builtin", "update:nodeBuiltin": "node scripts/update.mjs --environment=nodeBuiltin", + "update:worker": "node scripts/update.mjs --environment=worker", "build": "run-p \"build:*\"", "build:data": "node scripts/generate-data.mjs", "build:types": "node scripts/generate-types.mjs > index.d.ts" diff --git a/scripts/get-browser-globals.mjs b/scripts/get-browser-globals.mjs index 400020e..c49b7cd 100644 --- a/scripts/get-browser-globals.mjs +++ b/scripts/get-browser-globals.mjs @@ -101,7 +101,7 @@ const additionalGlobals = [ async function downloadBrowser({product} = {}) { const {downloadBrowser} = await import('puppeteer/internal/node/install.js'); - const {PUPPETEER_SKIP_DOWNLOAD, PUPPETEER_PRODUCT} = process.env; + const originalEnv = {...process.env}; try { process.env.PUPPETEER_SKIP_DOWNLOAD = JSON.stringify(false); if (product) { @@ -110,17 +110,35 @@ async function downloadBrowser({product} = {}) { await downloadBrowser(); } finally { - process.env.PUPPETEER_SKIP_DOWNLOAD = PUPPETEER_SKIP_DOWNLOAD; - process.env.PUPPETEER_PRODUCT = PUPPETEER_PRODUCT; + for (const env of ['PUPPETEER_SKIP_DOWNLOAD', 'PUPPETEER_PRODUCT']) { + if (Object.hasOwn(originalEnv)) { + process.env[env] = originalEnv[env]; + } else { + delete process.env[env]; + } + } } } -async function navigateToSecureContext(page) { +async function navigateToSecureContext(page, responses) { const port = await getPort(); const server = http.createServer((request, response) => { - response.statusCode = 200; - response.setHeader('Content-Type', 'text/plain'); - response.end('Hello World\n'); + const {url} = request; + if (responses?.[url]) { + const {contentType, content} = responses[url]; + response.statusCode = 200; + response.setHeader('Content-Type', contentType); + response.end(content); + return; + } + + if (url === '/') { + response.statusCode = 200; + response.setHeader('Content-Type', 'text/html'); + response.end(''); + } + + response.statusCode = 404; }); // https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts @@ -164,7 +182,43 @@ async function runInBrowser(function_, {product, secureContext = false} = {}) { } } -export default async function getBrowserGlobals() { +async function runInWebWorker(function_) { + await downloadBrowser(); + + const browser = await puppeteer.launch(); + const page = await browser.newPage(); + + let server; + let worker; + try { + server = await navigateToSecureContext(page); + assert.ok( + server.isSecureContext, + 'Expected a secure server.', + ); + + worker = await new Promise(resolve => { + page.on('workercreated', worker => { + resolve(worker); + }); + // eslint-disable-next-line no-undef -- execute in broswer + page.evaluate(() => new Worker('data:application/javascript,;')); + }); + + assert.ok( + await worker.evaluate(() => globalThis.isSecureContext), + 'Expected a secure worker.', + ); + + return await worker.evaluate(function_); + } finally { + await worker?.close(); + await browser.close(); + await server?.close(); + } +} + +async function getBrowserGlobals() { const chromeGlobals = await runInBrowser(getGlobalThisProperties, {secureContext: true}); const firefoxGlobals = await runInBrowser(getGlobalThisProperties, {product: 'firefox', secureContext: true}); @@ -182,3 +236,27 @@ export default async function getBrowserGlobals() { ); } +async function getWebWorkerGlobals() { + const properties = await runInWebWorker(getGlobalThisProperties); + + return createGlobals( + [ + ...properties, + // Existing data, need confirm + 'applicationCache', + 'onclose', + 'onconnect', + 'onoffline', + 'ononline', + 'PerformanceNavigation', + 'PerformanceTiming', + ], + { + shouldExclude: name => name.startsWith('__'), + isWritable: name => name.startsWith('on'), + excludeBuiltins: true, + }, + ); +} + +export {getBrowserGlobals, getWebWorkerGlobals}; diff --git a/scripts/update.mjs b/scripts/update.mjs index 74fe893..477df10 100644 --- a/scripts/update.mjs +++ b/scripts/update.mjs @@ -3,7 +3,7 @@ import {outdent} from 'outdent'; import {execaCommand} from 'execa'; import getBuiltinGlobals from './get-builtin-globals.mjs'; import getNodeBuiltinGlobals from './get-node-builtin-globals.mjs'; -import getBrowserGlobals from './get-browser-globals.mjs'; +import {getBrowserGlobals, getWebWorkerGlobals} from './get-browser-globals.mjs'; import {updateGlobals} from './utilities.mjs'; const ALL_JOBS = [ @@ -19,6 +19,10 @@ const ALL_JOBS = [ environment: 'browser', getGlobals: getBrowserGlobals, }, + { + environment: 'worker', + getGlobals: getWebWorkerGlobals, + }, ]; async function run(options) {