JavaScript SDK reference
@revokegpt/js is a typed wrapper over the RevokeGPT browser script. It loads the script once, renders widgets and
gives you a response token. It has no runtime dependencies and ships ESM and CommonJS. For a walkthrough, see the
JavaScript quickstart.
Install
Section titled “Install”npm install @revokegpt/js # after the first releaseExports
Section titled “Exports”load, render, challengeAccount, RevokeGPTLoadError, DEFAULT_ORIGIN, and the types Badge, ChallengeAccountOptions, LoadOptions, Locale, RenderOptions, RevokeGPTApi, Size, Theme, Widget.
Options
Section titled “Options”load options
Section titled “load options”| Option | Type | Default | Meaning |
|---|---|---|---|
origin |
string |
https://js.revokegpt.com |
Widget origin. A bare https: origin only (no path, query or credentials). http://localhost:* is accepted only when process.env.NODE_ENV !== 'production'. |
nonce |
string |
none | Set on the injected script as its CSP nonce. |
hl |
Locale |
none | Default language for widgets that set none. |
render options
Section titled “render options”| Option | Type | Default | Meaning |
|---|---|---|---|
sitekey |
string |
required | Your site key (rgpk_ plus 20 letters or digits). |
theme |
'light' | 'dark' | 'auto' |
none | Widget theme. |
size |
'normal' | 'compact' | 'invisible' |
invisible |
normal and compact are the checkbox frame; invisible is a hidden frame plus a badge. |
tabindex |
number |
none | Tab order of the frame. |
badge |
'bottomright' | 'bottomleft' | 'inline' |
bottomright |
Invisible size only. |
hl |
Locale |
the hl given to load() |
Widget language, one of the 28 launch locales. |
action |
string |
none | The action the token is issued for. Your server checks it. |
cdata |
string |
none | Optional string passed with the widget. |
callback |
(token: string) => void |
none | Receives the response token. |
expired-callback |
() => void |
none | The token expired and was dropped. |
error-callback |
(code: string) => void |
none | Receives the error code, for example network-error. |
title |
string |
none | Optional widget title. |
responseField |
'revokegpt-response' | 'g-recaptcha-response' |
revokegpt-response |
Name of the hidden response field. |
isolated |
boolean |
none | The widget has no part in the loader’s default widget rule. |
session |
boolean |
false |
Keep a firewall session: the loader runs a hidden session widget at load and again 300 s before each session token expires while the tab is visible, and hands the token to your integration or sets the __Host-rg_s cookie. See session tokens and cookies. |
challengeAccount options
Section titled “challengeAccount options”| Option | Type | Default | Meaning |
|---|---|---|---|
requestToken |
string |
required | The requestToken of an assessment’s accountVerification.endpoints entry. |
container |
Element | string |
the body | Holds the temporary response field of the dialog’s hidden widget. |
languageCode |
Locale |
the hl given to load() |
Dialog language. |
Methods
Section titled “Methods”function load(opts?: LoadOptions): Promise<RevokeGPTApi>Injects <script src="<origin>/v1/api.js"> once and resolves with the loader (window.revokegpt) when it is ready.
It is memoised: a second call returns the same load. It rejects with RevokeGPTLoadError on a bad origin, a script
error or after 15 seconds, and a failed load can be retried.
await load({ nonce: document.querySelector<HTMLMetaElement>('meta[name=csp-nonce]')?.content });render
Section titled “render”function render(el: Element, opts: RenderOptions): WidgetRenders a widget into el and returns a Widget. Call it after await load(); before that it throws
RevokeGPTLoadError.
Widget member |
Signature | Meaning |
|---|---|---|
id |
number |
The widget id. |
execute |
() => Promise<string> |
Runs the challenge and resolves with the response token. |
reset |
() => void |
Resets the widget. |
getResponse |
() => string |
The live token, or '' when there is none. |
destroy |
() => void |
Removes the widget. Safe to call more than once. After it, execute rejects and getResponse gives ''. |
const widget = render(document.getElementById('captcha')!, { sitekey: 'rgpk_...', action: 'login', callback: (token) => console.log(token),});const token = await widget.execute(); // send it to your server and verify it therewidget.destroy();challengeAccount
Section titled “challengeAccount”function challengeAccount(sitekey: string, opts: ChallengeAccountOptions): Promise<string>Runs the email-code step of account verification. A dialog asks for the code the service emailed, and the promise
resolves with the verification token. Your server presents that token in a following assessment of the same account;
success or failure is read there, not here. It rejects with Error('cancelled') when the person cancels and with
Error('busy') while another dialog is open. Call it after await load().
Errors and failure model
Section titled “Errors and failure model”loadrejects withRevokeGPTLoadError(nameis'RevokeGPTLoadError'): bad origin,window.revokegptnot the loader, script error, timeout.renderandchallengeAccountthrow or reject withRevokeGPTLoadErrorwhen the script is not loaded;challengeAccountalso does when the loaded loader release has nochallengeAccount.- Widget errors arrive through
error-callbackas a code string. See errors. execute()on a destroyed widget rejects withError('widget was destroyed').challengeAccountrejects withError('cancelled')orError('busy'), as above.
Configuration
Section titled “Configuration”There are no environment variables to set. The only setting that reads the build environment is the localhost rule for
origin; where there is no process, the page counts as production.
Content Security Policy:
script-src: allow the widget origin, or passnoncetoload(). The loader copies it onto everything it adds.frame-src: allow the widget origin; each widget is an iframe from it.
Security notes
Section titled “Security notes”- The token is only a claim until your server verifies it with an SDK such as Node.js or with siteverify. Never trust it in the browser.
originaccepts a barehttps:origin only.javascript:,data:andhttp:are rejected before anything is injected.- There is no option to load the script from an arbitrary URL.