From fa2641b9aefd5bee776ca75258272bc67c986982 Mon Sep 17 00:00:00 2001 From: ACTCD <101378590+ACTCD@users.noreply.github.com> Date: Sun, 15 Oct 2023 21:47:00 +0800 Subject: [PATCH 1/2] fix: correctly returns xhr errors when type is blob fix issue #555 --- .../Safari-Extension/Resources/background.js | 27 +++++++++------- xcode/Safari-Extension/Resources/content.js | 31 ++++++++++--------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/xcode/Safari-Extension/Resources/background.js b/xcode/Safari-Extension/Resources/background.js index 5e0a8feb..463210c5 100644 --- a/xcode/Safari-Extension/Resources/background.js +++ b/xcode/Safari-Extension/Resources/background.js @@ -414,18 +414,21 @@ function handleMessage(request, sender, sendResponse) { if (["", "text"].indexOf(xhr.responseType) !== -1) { x.responseText = xhr.responseText; } - // need to convert arraybuffer data to postMessage - if (xhr.responseType === "arraybuffer") { - const arr = Array.from(new Uint8Array(xhr.response)); - x.response = arr; - } - // need to blob arraybuffer data to postMessage - if (xhr.responseType === "blob") { - const base64data = await readAsDataURL(xhr.response); - x.response = { - data: base64data, - type: xhr.responseType - }; + // only process when xhr is complete and data exist + if (xhr.readyState === 4 && xhr.response !== null) { + // need to convert arraybuffer data to postMessage + if (xhr.responseType === "arraybuffer") { + const arr = Array.from(new Uint8Array(xhr.response)); + x.response = arr; + } + // need to convert blob data to postMessage + if (xhr.responseType === "blob") { + const base64data = await readAsDataURL(xhr.response); + x.response = { + data: base64data, + type: xhr.responseType + }; + } } port.postMessage({name: e, event, response: x}); }; diff --git a/xcode/Safari-Extension/Resources/content.js b/xcode/Safari-Extension/Resources/content.js index 2060a321..311b1eb4 100644 --- a/xcode/Safari-Extension/Resources/content.js +++ b/xcode/Safari-Extension/Resources/content.js @@ -160,21 +160,24 @@ const apis = { ) { // process xhr response const r = msg.response; - if (r.responseType === "arraybuffer") { - // arraybuffer responses had their data converted in background - // convert it back to arraybuffer - try { - const buffer = new Uint8Array(r.response).buffer; - r.response = buffer; - } catch (err) { - console.error("error parsing xhr arraybuffer", err); + // only process when xhr is complete and data exist + if (r.readyState === 4 && r.response !== null) { + if (r.responseType === "arraybuffer") { + // arraybuffer responses had their data converted in background + // convert it back to arraybuffer + try { + const buffer = new Uint8Array(r.response).buffer; + r.response = buffer; + } catch (err) { + console.error("error parsing xhr arraybuffer", err); + } + } else if (r.responseType === "blob" && r.response.data) { + // blob responses had their data converted in background + // convert it back to blob + const resp = await fetch(r.response.data); + const b = await resp.blob(); + r.response = b; } - } else if (r.responseType === "blob" && r.response.data) { - // blob responses had their data converted in background - // convert it back to blob - const resp = await fetch(r.response.data); - const b = await resp.blob(); - r.response = b; } // call userscript method details[msg.name](msg.response); From 28c705ddff90a93b5dbf08cd81c97173624a00a9 Mon Sep 17 00:00:00 2001 From: ACTCD <101378590+ACTCD@users.noreply.github.com> Date: Sun, 15 Oct 2023 22:18:30 +0800 Subject: [PATCH 2/2] build: v4.4.5(82), v1.4.5(56) --- xcode/Safari-Extension/Resources/manifest.json | 2 +- xcode/xcconfig/Userscripts-Release.xcconfig | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/xcode/Safari-Extension/Resources/manifest.json b/xcode/Safari-Extension/Resources/manifest.json index 85e80919..6e1cbf9c 100644 --- a/xcode/Safari-Extension/Resources/manifest.json +++ b/xcode/Safari-Extension/Resources/manifest.json @@ -4,7 +4,7 @@ "default_locale": "en", "name": "__MSG_extension_name__", "description": "__MSG_extension_description__", - "version": "4.4.4", + "version": "4.4.5", "icons": { "48": "images/icon-48.png", "96": "images/icon-96.png", diff --git a/xcode/xcconfig/Userscripts-Release.xcconfig b/xcode/xcconfig/Userscripts-Release.xcconfig index 516d42eb..2ca80325 100644 --- a/xcode/xcconfig/Userscripts-Release.xcconfig +++ b/xcode/xcconfig/Userscripts-Release.xcconfig @@ -1,10 +1,10 @@ #include "Userscripts-Base.xcconfig" INFOPLIST_KEY_NSHumanReadableCopyright = Copyright © 2018–2023 Justin Wasack. All rights reserved. -IOS_APP_BUILD = 53 -IOS_APP_VERSION = 1.4.4 -MAC_APP_BUILD = 80 -MAC_APP_VERSION = 4.4.4 +IOS_APP_BUILD = 56 +IOS_APP_VERSION = 1.4.5 +MAC_APP_BUILD = 82 +MAC_APP_VERSION = 4.4.5 // Developer Team ID DEVELOPMENT_TEAM = J74Q8V8V8N