Skip to content

Commit 1bf8173

Browse files
committed
some fixes, v7.5.1
1 parent d8d788e commit 1bf8173

File tree

7 files changed

+38
-33
lines changed

7 files changed

+38
-33
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sp-editor",
3-
"version": "7.5.0",
3+
"version": "7.5.1",
44
"private": true,
55
"homepage": ".",
66
"dependencies": {

public/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "SP Editor",
33
"homepage_url": "https://microsoftedge.microsoft.com/addons/detail/affnnhcbfmcbbdlcadgkdbfafigmjdkk",
4-
"version": "7.5.0",
4+
"version": "7.5.1",
55
"description": "Create and update SharePoint Online/SP2013/SP2016/SP2019 css/js files, inject files to web, manage web/list properties, list Webhook",
66
"manifest_version": 3,
77
"devtools_page": "devtools.html",

src/pages/proxy/chrome/addproxy.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ export const addProxyScript = (proxies: IProxy[], enabled: boolean, update?: boo
1212
}
1313
}
1414

15+
function safeParseHeaders(headers: string | undefined): Headers | undefined {
16+
if (!headers) return undefined;
17+
try {
18+
return new Headers(JSON.parse(headers));
19+
} catch (error) {
20+
console.error('Failed to parse headers:', error);
21+
return undefined;
22+
}
23+
}
24+
1525
if (!enabled) {
1626
if ((window as any).__fetchInterceptorRegistered) {
1727
window.fetch = (window as any).__originalFetch;
@@ -44,14 +54,14 @@ export const addProxyScript = (proxies: IProxy[], enabled: boolean, update?: boo
4454

4555
for (const proxy of proxies) {
4656
const methodMatches = proxy.methods.includes('ALL') || proxy.methods.includes(method);
47-
if (proxy.enabled && url && url.indexOf(proxy.url) > -1 && methodMatches && shouldFail(proxy.failRate)) {
57+
if (proxy.enabled && url && url.indexOf(proxy.url.trim()) > -1 && methodMatches && shouldFail(proxy.failRate)) {
4858
console.warn(`SP Editor blocked ${url}`);
4959
return new Response(
50-
JSON.stringify(proxy.responseBody),
60+
proxy.responseBody,
5161
{
5262
status: Number(proxy.status),
5363
statusText: proxy.statusText,
54-
headers: proxy.responseHeaders,
64+
headers: safeParseHeaders(proxy.responseHeaders),
5565
}
5666
);
5767
}

src/pages/proxy/chrome/chrome-actions.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,15 @@ import { addProxyScript } from './addproxy';
77
let listener: (tabId: number, changeInfo: any, tab: any) => void; // Listener reference
88

99
export async function addProxy(dispatch: Dispatch<ProxyActions | HomeActions>, enabled: boolean, payload: IProxy[], update?: boolean) {
10-
if ((enabled && !chrome.tabs.onUpdated.hasListeners()) || (enabled && update)) {
11-
if (chrome.tabs.onUpdated.hasListeners()) {
12-
chrome.tabs.onUpdated.removeListener(listener);
13-
}
14-
10+
if ((enabled)) {
11+
chrome.tabs.onUpdated.removeListener(listener);
1512
listener = (tabId, changeInfo, tab) => {
1613
if (changeInfo.status === 'complete' && tab.active) {
1714
executeScript(dispatch, enabled, payload, false);
1815
}
1916
};
20-
if(!chrome.tabs.onUpdated.hasListeners()) {
21-
chrome.tabs.onUpdated.addListener(listener);
22-
}
23-
} else if (!enabled && chrome.tabs.onUpdated.hasListeners()) {
17+
chrome.tabs.onUpdated.addListener(listener);
18+
} else {
2419
chrome.tabs.onUpdated.removeListener(listener);
2520
}
2621

src/pages/proxy/components/editpanel.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ const ProxyEditPanel = () => {
2626
url: '/_api/',
2727
status: '200',
2828
statusText: 'OK',
29-
responseHeaders: {
29+
responseHeaders: JSON.stringify({
3030
'Content-Type': 'application/json',
31-
},
32-
responseBody: {
31+
}),
32+
responseBody: JSON.stringify({
3333
message: 'Success',
34-
},
34+
}),
3535
description: '',
3636
});
3737

@@ -74,7 +74,7 @@ const ProxyEditPanel = () => {
7474
}
7575

7676
const data = await response.json();
77-
setSampleData(data);
77+
setSampleData(JSON.stringify(data, null, 2));
7878
} catch (error) {
7979
setSampleData(undefined);
8080
}
@@ -244,9 +244,9 @@ const ProxyEditPanel = () => {
244244
label="Response Headers"
245245
multiline
246246
autoAdjustHeight
247-
value={JSON.stringify(localProxy.responseHeaders, null, 2)}
247+
value={typeof localProxy.responseHeaders === 'object' ? JSON.stringify(localProxy.responseHeaders, null, 2) : localProxy.responseHeaders}
248248
onChange={(e, newValue) =>
249-
setLocalProxy({ ...localProxy, responseHeaders: newValue ? JSON.parse(newValue) : {} })
249+
setLocalProxy({ ...localProxy, responseHeaders: newValue ?? '' })
250250
}
251251
styles={{ root: { width: '100%' } }}
252252
/>
@@ -255,9 +255,9 @@ const ProxyEditPanel = () => {
255255
label="Response Body"
256256
multiline
257257
autoAdjustHeight
258-
value={JSON.stringify(localProxy.responseBody, null, 2)}
258+
value={typeof localProxy.responseBody === 'object' ? JSON.stringify(localProxy.responseBody, null, 2) : localProxy.responseBody}
259259
onChange={(e, newValue) =>
260-
setLocalProxy({ ...localProxy, responseBody: newValue ? JSON.parse(newValue) : {} })
260+
setLocalProxy({ ...localProxy, responseBody: newValue ?? '' })
261261
}
262262
styles={{ root: { width: '100%' } }}
263263
/>

src/store/proxy/reducers.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ const defaultProxy: IProxy[] = [{
77
url: '/_api/',
88
status: '429',
99
statusText: 'Too many requests',
10-
responseHeaders: {
10+
responseHeaders: JSON.stringify({
1111
'Content-Type': 'application/json',
1212
'Retry-After': '2', // Tell the client to wait 2 seconds
13-
},
14-
responseBody: {
13+
}),
14+
responseBody: JSON.stringify({
1515
error: {
1616
code: '-2147024860, Microsoft.SharePoint.SPQueryThrottledException',
1717
message: {
@@ -20,7 +20,7 @@ const defaultProxy: IProxy[] = [{
2020
'The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator.',
2121
},
2222
},
23-
},
23+
}),
2424
description: 'Default 429 proxy, please edit to suit your needs',
2525
},
2626
{
@@ -30,10 +30,10 @@ const defaultProxy: IProxy[] = [{
3030
url: 'https://graph.microsoft.com/v1.0/me',
3131
status: '200',
3232
statusText: 'OK',
33-
responseHeaders: {
33+
responseHeaders: JSON.stringify({
3434
'Content-Type': 'application/json',
35-
},
36-
responseBody: {
35+
}),
36+
responseBody: JSON.stringify({
3737
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users/$entity",
3838
"businessPhones": [
3939
"+1 412 555 0109"
@@ -48,7 +48,7 @@ const defaultProxy: IProxy[] = [{
4848
"surname": "Bowen",
4949
"userPrincipalName": "[email protected]",
5050
"id": "48d31887-5fad-4d73-a9f5-3c356e68a038"
51-
},
51+
}),
5252
description: 'Default 200 proxy, please edit to suit your needs',
5353
}
5454
];

src/store/proxy/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export interface IProxy {
1010
url: string
1111
status: string
1212
statusText: string
13-
responseHeaders: HeadersInit
14-
responseBody: any
13+
responseHeaders: string
14+
responseBody: string
1515
enabled?: boolean
1616
description?: string
1717
}

0 commit comments

Comments
 (0)