Skip to content

Commit

Permalink
Better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
madmath committed Jan 22, 2025
1 parent 076fd60 commit 15b3154
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
20 changes: 14 additions & 6 deletions src/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ chrome.devtools.inspectedWindow.eval(
}

addEventListenerToButtons();
setupNavigationListener();
}
},
);
Expand All @@ -49,10 +50,8 @@ function getInspectedWindowURL(): Promise<URL> {
}

async function refreshPanel() {
let node = document.querySelector(selectors.initialMessage)
while (node && node.firstChild) {
node.removeChild(node.firstChild);
}
document.querySelector(selectors.initialMessage)!.classList.add('hide');
document.querySelector(selectors.speedscopeWrapper)!.classList.add('hide');
document
.querySelector(selectors.speedscopeWrapper)!
.classList.add('loading-fade');
Expand All @@ -67,7 +66,7 @@ async function refreshPanel() {
const speedscopeIframe = document.getElementById('speedscope-iframe') as HTMLIFrameElement;
speedscopeIframe.contentWindow?.postMessage({
type: 'loadProfile',
profileData: profileData
profileData: JSON.stringify(profileData)
}, '*');

document
Expand All @@ -76,7 +75,6 @@ async function refreshPanel() {

} catch (error) {
console.error(error);
document.querySelector(selectors.speedscopeWrapper)!.classList.add('hide');
document
.querySelector(selectors.notProfilableMessage)!
.classList.remove('hide');
Expand All @@ -86,4 +84,14 @@ async function refreshPanel() {
document
.querySelector(selectors.speedscopeWrapper)!
.classList.remove('loading-fade');
}

function setupNavigationListener() {
chrome.devtools.network.onNavigated.addListener(() => {
// Reset panel to initial state
document.querySelector(selectors.speedscopeWrapper)!.classList.add('hide');
document.querySelector(selectors.loadingAnimation)!.classList.add('hide');
document.querySelector(selectors.notProfilableMessage)!.classList.add('hide');
document.querySelector(selectors.initialMessage)!.classList.remove('hide');
});
}
3 changes: 2 additions & 1 deletion src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export enum RenderBackend {

export const env = {
OAUTH2_DOMAIN: 'accounts.shopify.com',
DEV_OAUTH2_DOMAIN: 'identity.myshopify.io',
//DEV_OAUTH2_DOMAIN: 'identity.myshopify.io',
DEV_OAUTH2_DOMAIN: 'identity.shopify-identity-uwam.mathieu-perreault.us.spin.dev',
OAUTH2_CLIENT_ID: 'ff2a91a2-6854-449e-a37d-c03bcd181126',
DEV_OAUTH2_CLIENT_ID: '1d7f695c-42e2-493a-a6dc-be12d4117d58',
OAUTH2_SUBJECT_ID: {
Expand Down
24 changes: 16 additions & 8 deletions src/utils/getProfileData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@ import {SubjectAccessToken} from 'types';
import { CoreAccessTokenResponse } from '../types/messages';

export async function getProfileData(
url: URL): Promise<string> {
url: URL): Promise<any> {

const fetchOptions = {
headers: {
Accept: 'application/vnd.speedscope+json',
Authorization: `Bearer ${await requestAccessToken(url).then(({accessToken}) => accessToken)}`,
},
};
try {
const fetchOptions = {
headers: {
Accept: 'application/vnd.speedscope+json',
Authorization: `Bearer ${await requestAccessToken(url).then(({accessToken}) => accessToken)}`,
},
};

return fetch(url.href, fetchOptions).then(response => response.text());
const response = await fetch(url.href, fetchOptions);
if (!response.ok) {
throw new Error('Not profilable');
}
return response.json();
} catch (error) {
throw new Error('Not profilable');
}
}

function requestAccessToken(
Expand Down

0 comments on commit 15b3154

Please sign in to comment.