Skip to content

Commit

Permalink
fix: update send headers listener for firefox to retrieve auth (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdrani authored Oct 12, 2023
1 parent 8b89838 commit 5bb16d1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
11 changes: 4 additions & 7 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,12 @@ chrome.webRequest.onBeforeRequest.addListener(details => {
)

chrome.webRequest.onBeforeSendHeaders.addListener(details => {
details?.requestHeaders?.forEach(header => {
if (!header?.value?.startsWith('Bearer')) return
const authHeader = details?.requestHeaders?.find(header => header?.name == 'authorization')
if (!authHeader) return

if (details?.initiator?.match(/.*:\/\/.*spotify.com.*/)) {
chrome.storage.local.set({ auth_token: header?.value })
}
})
chrome.storage.local.set({ auth_token: authHeader?.value })
},
{ urls: ['https://api-partner.spotify.com/pathfinder/v1/*'] },
{ urls: ['https://guc3-spclient.spotify.com/track-playback/v1/devices'] },
['requestHeaders']
)

Expand Down
6 changes: 3 additions & 3 deletions src/observers/song-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ export default class SongTracker {
type: 'play',
body: {
uris: [`spotify:track:${trackId}`],
position_ms: Math.max(parseInt(startTime, 10) - 1, 0) * 1000,
position_ms: Math.max(parseInt(startTime, 10), 0) * 1000,
},
cb: () => { this.#mute(); setTimeout(() => this.#unMute(), 1000) }
cb: () => { this.#mute(); setTimeout(() => this.#unMute(), 250) }
})
}

Expand All @@ -100,7 +100,7 @@ export default class SongTracker {
const currentPosition = timeToSeconds(this.#playbackPosition?.textContent || '0:00')
const currentPositionTime = parseInt(currentPosition, 10) * 1000

if (currentPositionTime < parsedStartTime) {
if (parsedStartTime != 0 && currentPositionTime < parsedStartTime) {
await this.#seekTo(startTime)
} else {
this.#unMute()
Expand Down

0 comments on commit 5bb16d1

Please sign in to comment.