diff --git a/README.md b/README.md index b923c22..da45b23 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ This is a JavaScript library to easily configure the loading of the [hCaptcha](h 1. [Installation](#installation) 2. [Implementation](#implementation) 3. [Props](#props) +3. [Legacy Support](#legacy-support) ### Installation ``` @@ -30,19 +31,83 @@ const { response } = await hcaptcha.execute({ async: true }); ``` ### Props -| Name | Values/Type | Required | Default | Description | -|-------------------|-------------|----------|-----------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------| -| `loadAsync` | Boolean | No | `true` | Set if the script should be loaded asynchronously. | -| `cleanup` | Boolean | No | `true` | Remove script tag after setup. | -| `crossOrigin` | String | No | `-` | Set script cross origin attribute such as "anonymous". | -| `scriptLocation` | HTMLElement | No | `document.head` | Location of where to append the script tag. Make sure to add it to an area that will persist to prevent loading multiple times in the same document view. | -| `apihost` | String | No | `-` | See enterprise docs. | -| `assethost` | String | No | `-` | See enterprise docs. | -| `endpoint` | String | No | `-` | See enterprise docs. | -| `hl` | String | No | `-` | See enterprise docs. | -| `host` | String | No | `-` | See enterprise docs. | -| `imghost` | String | No | `-` | See enterprise docs. | -| `recaptchacompat` | String | No | `-` | See enterprise docs. | -| `reportapi` | String | No | `-` | See enterprise docs. | -| `sentry` | Boolean | No | `-` | See enterprise docs. | -| `custom` | Boolean | No | `-` | See enterprise docs. | +| Name | Values/Type | Required | Default | Description | +|-------------------|-------------|----------|------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------| +| `loadAsync` | Boolean | No | `true` | Set if the script should be loaded asynchronously. | +| `cleanup` | Boolean | No | `true` | Remove script tag after setup. | +| `crossOrigin` | String | No | `-` | Set script cross origin attribute such as "anonymous". | +| `scriptSource` | String | No | `https://js.hcaptcha.com/1/api.js` | Set script source URI. Takes precedence over `secureApi`. | +| `scriptLocation` | HTMLElement | No | `document.head` | Location of where to append the script tag. Make sure to add it to an area that will persist to prevent loading multiple times in the same document view. | +| `secureApi` | Boolean | No | `false` | See enterprise docs. | +| `apihost` | String | No | `-` | See enterprise docs. | +| `assethost` | String | No | `-` | See enterprise docs. | +| `endpoint` | String | No | `-` | See enterprise docs. | +| `hl` | String | No | `-` | See enterprise docs. | +| `host` | String | No | `-` | See enterprise docs. | +| `imghost` | String | No | `-` | See enterprise docs. | +| `recaptchacompat` | String | No | `-` | See enterprise docs. | +| `reportapi` | String | No | `-` | See enterprise docs. | +| `sentry` | Boolean | No | `-` | See enterprise docs. | +| `custom` | Boolean | No | `-` | See enterprise docs. | + + + +## Legacy Support +In order to support older browsers, a separate bundle is generated in which all ES6 code is compiled down to ES5 along with an optional polyfill bundle. + +- `polyfills.js`: Provides polyfills for features not supported in older browsers. +- `index.es5.js`: **@hcaptcha/loader** package compiled for ES5 environments. + +### Import Bundle(s) +Both bundles generated use IIFE format rather than a more modern import syntax such as `require` or `esm`. + +```js +// Optional polyfill import +import '@hCaptcha/loader/dist/polyfills.js'; +// ES5 version of hCaptcha Loader +import '@hCaptcha/loader/dist/index.es5.js'; + +hCaptchaLoader().then(function(hcaptcha) { + var element = document.createElement('div'); + // hCaptcha API is ready + hcaptcha.render(element, { + sitekey: 'YOUR_SITE_KEY', + // Additional options here + }); +}); + +``` +### TypeScript +To handle typescript with ES5 version, use the following statement. +```ts +declare global { + interface Window { + hCaptchaLoader: any; + } +} +``` + +### CDN +The hCaptcha Loader targeted for older browsers can also be imported via CDN by using [UNPKG](https://www.unpkg.com/), see example below. + + +```html + +
+ + + + + + + +