From 6fafcaf1e3618d08c08d5e8dc1b45b208d43edf0 Mon Sep 17 00:00:00 2001 From: SamYSF <98792230+SamYSF@users.noreply.github.com> Date: Wed, 3 Apr 2024 11:26:27 +0800 Subject: [PATCH] fix: getAttribute error (#25) --- src/oauth.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/oauth.js b/src/oauth.js index 447c185..1141e57 100644 --- a/src/oauth.js +++ b/src/oauth.js @@ -119,9 +119,11 @@ let accessToken; let applicationName; function getDomAccessToken() { - if(window.location.pathname != "/src/popup.html"){ - accessToken = document.getElementById("CasdoorAccessToken").getAttribute("value"); - applicationName = document.getElementById("CasdoorApplicationName").getAttribute("value"); + const accessTokenDom = document.getElementById("CasdoorAccessToken") + const applicationNameDom = document.getElementById("CasdoorApplicationName") + if(window.location.pathname != "/src/popup.html" && accessTokenDom && applicationNameDom){ + accessToken = accessTokenDom.getAttribute("value"); + applicationName = applicationNameDom.getAttribute("value"); if (accessToken && applicationName) { sdk.getUserProfile(accessToken).then((userProfile) => { userProfile.applicationName = applicationName;