You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Run the following code before loading webcrypto-liner
constMaybeWorkerGlobalScope=Object.getPrototypeOf(Object.getPrototypeOf(globalThis))constcrypto=Object.getOwnPropertyDescriptor(MaybeWorkerGlobalScope,'crypto')// The crypto is defined in [WorkerGlobalScope], let's move it to [DedicatedWorkerGlobalScope]if(crypto){deleteMaybeWorkerGlobalScope.cryptoObject.defineProperty(globalThis,'crypto',crypto)}
https://github.com/PeculiarVentures/webcrypto-liner/blob/faae2d4b127c1830ceb2fad4736d6177feab3544/src/shim.ts#L11-18
Source code:
In the mainframe,
crypto.*
is defined on the Window interface andself
orwindow
has the prototype of Window therefore everything is fine.In Web Worker,
crypto.*
is defined on the WorkerGlobalScope, butself
is not direct instance ofWorkerGlobalScope
:The prototype chain is:
self
=> DedicatedWorkerGlobalScope => WorkerGlobalScopeTherefore
delete self.crypto
doesn't work sincecrypto
is not defined on theDedicatedWorkerGlobalScope
butWorkerGlobalScope
.After the deletion implicitly failed (
delete
op return true for non-existence property, in this case,crypto
)Line 13
window.crypto = new Crypto();
failed to run becauseWorkerGlobalScope.crypto
is a configurable getter but no setter.The text was updated successfully, but these errors were encountered: