Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite committed Feb 5, 2024
1 parent c40cedd commit ef5cea3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/extensions/toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,23 @@ export class Toolbar {
// only load the toolbar once, even if there are multiple instances of PostHogLib
assignableWindow['_postHogToolbarLoaded'] = true

const host = this.instance.requestRouter.endpointFor('assets')
// toolbar.js is served from the PostHog CDN, this has a TTL of 24 hours.
// the toolbar asset includes a rotating "token" that is valid for 5 minutes.
const fiveMinutesInMillis = 5 * 60 * 1000
// this ensures that we bust the cache periodically
const timestampToNearestFiveMinutes = Math.floor(Date.now() / fiveMinutesInMillis) * fiveMinutesInMillis
const toolbarUrl = `${host}/static/toolbar.js?t=${timestampToNearestFiveMinutes}`
const toolbarUrl = this.instance.requestRouter.endpointFor(
'assets',
`/static/toolbar.js?t=${timestampToNearestFiveMinutes}`
)
const disableToolbarMetrics =
this.instance.requestRouter.region === 'custom' && this.instance.config.advanced_disable_toolbar_metrics

// TODO: Dos the toolbar use the ingestion APIs?
const toolbarParams = {
token: this.instance.config.token,
...params,
apiURL: host, // defaults to api_host from the instance config if nothing else set
apiURL: this.instance.requestRouter.endpointFor('api'), // defaults to api_host from the instance config if nothing else set
...(disableToolbarMetrics ? { instrument: false } : {}),
}

Expand Down

0 comments on commit ef5cea3

Please sign in to comment.