diff --git a/src/actions/zipped-profiles.ts b/src/actions/zipped-profiles.ts index acde01eee1..5353348dba 100644 --- a/src/actions/zipped-profiles.ts +++ b/src/actions/zipped-profiles.ts @@ -57,7 +57,7 @@ export function viewProfileFromZip( try { // Attempt to unserialize the profile. const profile = await unserializeProfileOfArbitraryFormat( - await file.async('uint8array'), + await file.async('arraybuffer'), pathInZipFile ); diff --git a/src/profile-logic/process-profile.ts b/src/profile-logic/process-profile.ts index 709b3c048e..8a89feae17 100644 --- a/src/profile-logic/process-profile.ts +++ b/src/profile-logic/process-profile.ts @@ -2005,10 +2005,12 @@ export async function unserializeProfileOfArbitraryFormat( upgradeInfo: ProfileUpgradeInfo = {} ): Promise { try { - // We used to use `instanceof ArrayBuffer`, but this doesn't work when the - // object is constructed from an ArrayBuffer in a different context... which - // happens in our tests. - if (String(arbitraryFormat) === '[object ArrayBuffer]') { + // We use Object.prototype.toString instead of `instanceof ArrayBuffer` + // because instanceof doesn't work cross-realm (e.g. in tests), and we + // can't use String() since that serializes the full contents of a Uint8Array. + if ( + Object.prototype.toString.call(arbitraryFormat) === '[object ArrayBuffer]' + ) { const arrayBuffer = arbitraryFormat as ArrayBuffer; arbitraryFormat = new Uint8Array(arrayBuffer); }