Skip to content

Commit 6437746

Browse files
committed
fix: refresh token after opening the official website to avoid expiration of authorization (#239)
1 parent c8a9873 commit 6437746

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/content-script/index.jsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,21 @@ async function getInput(inputQuery) {
100100
}
101101

102102
async function overwriteAccessToken() {
103-
if (location.hostname !== 'chat.openai.com' || location.pathname !== '/api/auth/session') return
104-
105-
const response = document.querySelector('pre').textContent
103+
if (location.hostname !== 'chat.openai.com') return
106104

107105
let data
108-
try {
109-
data = JSON.parse(response)
110-
} catch (error) {
111-
console.error('json error', error)
112-
return
106+
if (location.pathname === '/api/auth/session') {
107+
const response = document.querySelector('pre').textContent
108+
try {
109+
data = JSON.parse(response)
110+
} catch (error) {
111+
console.error('json error', error)
112+
}
113+
} else {
114+
const resp = await fetch('https://chat.openai.com/api/auth/session')
115+
data = await resp.json().catch(() => ({}))
113116
}
114-
if (data.accessToken) {
117+
if (data && data.accessToken) {
115118
await setAccessToken(data.accessToken)
116119
console.log(data.accessToken)
117120
}

0 commit comments

Comments
 (0)