@aimeloic/monkey-tester 5.0.0 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/htmlTemplate.js +13 -2
- package/package.json +1 -1
package/htmlTemplate.js
CHANGED
|
@@ -6,7 +6,12 @@
|
|
|
6
6
|
// const endpointsJsonB64 = encodePayload(endpointsData);
|
|
7
7
|
//
|
|
8
8
|
function encodePayload(obj) {
|
|
9
|
-
|
|
9
|
+
const jsonStr = JSON.stringify(obj);
|
|
10
|
+
// Convert string to UTF-8 bytes
|
|
11
|
+
const bytes = new TextEncoder().encode(jsonStr);
|
|
12
|
+
// Convert bytes to binary string for btoa
|
|
13
|
+
const binStr = Array.from(bytes, byte => String.fromCharCode(byte)).join('');
|
|
14
|
+
return btoa(binStr);
|
|
10
15
|
}
|
|
11
16
|
|
|
12
17
|
// The reciprocal decode runs inside each HTML template (see _decode below).
|
|
@@ -18,8 +23,14 @@ const _decode = `function _decode(b64){return JSON.parse(decodeURIComponent(esca
|
|
|
18
23
|
function runtimeClientSandbox() {
|
|
19
24
|
// Unicode-safe decode (whitespace-stripped for safety)
|
|
20
25
|
function _decode(b64) {
|
|
21
|
-
|
|
26
|
+
const binStr = atob(b64.replace(/\s+/g, ''));
|
|
27
|
+
const bytes = new Uint8Array(binStr.length);
|
|
28
|
+
for (let i = 0; i < binStr.length; i++) {
|
|
29
|
+
bytes[i] = binStr.charCodeAt(i);
|
|
22
30
|
}
|
|
31
|
+
const jsonStr = new TextDecoder().decode(bytes);
|
|
32
|
+
return JSON.parse(jsonStr);
|
|
33
|
+
}
|
|
23
34
|
|
|
24
35
|
const ENDPOINTS = _decode(
|
|
25
36
|
document.getElementById('__monkey_data__').getAttribute('data-payload')
|