-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: chrome extension build (#1386)
- Loading branch information
Showing
14 changed files
with
341 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#!/bin/bash | ||
|
||
curl -o vendor/honeybadger.min.js https://js.honeybadger.io/v3.2/honeybadger.min.js | ||
curl -o vendor/honeybadger.min.js https://js.honeybadger.io/v6.9/honeybadger.ext.min.js |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { Types, Util } from '@honeybadger-io/core' | ||
const { globalThisOrWindow } = Util | ||
|
||
export class BrowserFeedbackForm { | ||
|
||
private readonly config: Types.BrowserConfig | ||
private readonly logger: Types.Logger | ||
private readonly scriptUrl: string | ||
|
||
constructor(config: Types.BrowserConfig, logger: Types.Logger, scriptUrl: string) { | ||
this.config = config | ||
this.logger = logger | ||
this.scriptUrl = scriptUrl | ||
} | ||
|
||
/* ROLLUP_STRIP_CODE_CHROME_EXTENSION_START */ | ||
public show(lastNoticeId: string, options: Types.UserFeedbackFormOptions = {}) { | ||
if (!this.config || !this.config.apiKey) { | ||
this.logger.debug('Client not initialized') | ||
return | ||
} | ||
|
||
if (!lastNoticeId) { | ||
this.logger.debug("Can't show user feedback form without a notice already reported") | ||
return | ||
} | ||
|
||
const global = globalThisOrWindow() | ||
if (typeof global.document === 'undefined') { | ||
this.logger.debug('global.document is undefined. Cannot attach script') | ||
return | ||
} | ||
|
||
if (this.isUserFeedbackScriptUrlAlreadyVisible()) { | ||
this.logger.debug('User feedback form is already visible') | ||
return | ||
} | ||
|
||
global['honeybadgerUserFeedbackOptions'] = { | ||
...options, | ||
apiKey: this.config.apiKey, | ||
endpoint: this.config.userFeedbackEndpoint, | ||
noticeId: lastNoticeId, | ||
} | ||
|
||
this.appendUserFeedbackScriptTag(global, options) | ||
|
||
} | ||
|
||
private appendUserFeedbackScriptTag(window: typeof globalThis, options: Types.UserFeedbackFormOptions = {}) { | ||
const script = window.document.createElement('script') | ||
script.setAttribute('src', this.scriptUrl) | ||
script.setAttribute('async', 'true') | ||
if (options.onLoad) { | ||
script.onload = options.onLoad | ||
} | ||
(global.document.head || global.document.body).appendChild(script) | ||
} | ||
|
||
private isUserFeedbackScriptUrlAlreadyVisible() { | ||
const global = globalThisOrWindow() | ||
const feedbackScriptUrl = this.scriptUrl | ||
for (let i = 0; i < global.document.scripts.length; i++) { | ||
const script = global.document.scripts[i] | ||
if (script.src === feedbackScriptUrl) { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} | ||
/* ROLLUP_STRIP_CODE_CHROME_EXTENSION_END */ | ||
} |
Oops, something went wrong.