{"id":22096066,"url":"https://github.com/perimeterx/perimeterx-chrome-extension-demo","last_synced_at":"2025-09-16T04:09:34.949Z","repository":{"id":70060548,"uuid":"283150682","full_name":"PerimeterX/perimeterx-chrome-extension-demo","owner":"PerimeterX","description":"Demo project for Chrome Extension integration","archived":false,"fork":false,"pushed_at":"2021-03-30T13:15:55.000Z","size":85,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-24T00:55:21.316Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PerimeterX.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-28T08:31:16.000Z","updated_at":"2024-12-28T19:00:28.000Z","dependencies_parsed_at":"2023-02-22T07:00:21.471Z","dependency_job_id":null,"html_url":"https://github.com/PerimeterX/perimeterx-chrome-extension-demo","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/PerimeterX/perimeterx-chrome-extension-demo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerimeterX%2Fperimeterx-chrome-extension-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerimeterX%2Fperimeterx-chrome-extension-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerimeterX%2Fperimeterx-chrome-extension-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerimeterX%2Fperimeterx-chrome-extension-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PerimeterX","download_url":"https://codeload.github.com/PerimeterX/perimeterx-chrome-extension-demo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerimeterX%2Fperimeterx-chrome-extension-demo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275359343,"owners_count":25450552,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-16T02:00:10.229Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-01T04:09:35.368Z","updated_at":"2025-09-16T04:09:34.916Z","avatar_url":"https://github.com/PerimeterX.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![image](https://storage.googleapis.com/perimeterx-logos/primary_logo_red_cropped.png)\n\n# [PerimeterX](http://www.perimeterx.com) Whack-a-Bot Chrome Extension Demo\n\n\u003e This repository contains a sample Chrome Extension demonstrating how to integrate PerimeterX Bot Defender JavaScript sensor with Chrome Extension.\n\n![demo](https://whackabot.xyz/whackabot.gif)\n\n## Table of Contents\n\n-   [Getting Started](#gettingStarted)\n-   [Advanced Blocking Response](#advancedBlockingResponse)\n    -   [What Is Advanced Blocking Response?](#whatIsAdavancedBlockingResponse)\n    -   [Integration](#integration)\n    -   [Challenge Result Callback](#challengeResultCallback)\n-   [Optional Configuration](#optionalConfiguration)\n\n## Getting Started\n\nTo integrate the PerimeterX JavaScript sensor and Human Challenge, add the following snippet to the Chrome Extension main .js file:\n\n```javascript\n(function () {\n    // set according to your PerimeterX appid\n    window._pxAppId = '\u003cPerimeterX App id\u003e';\n    // sets PerimeterX captcha mode to on demand\n    window.pxHumanChallengeOnDemand = true;\n    // required PerimeterX scripts\n    let pxCaptcha = document.createElement('script');\n    pxCaptcha.type = 'text/javascript';\n    pxCaptcha.src = '/scripts/captcha.js';\n    let s = document.getElementsByTagName('script')[0];\n    s.parentNode.insertBefore(pxCaptcha, s);\n    let sensor = document.createElement('script');\n    sensor.type = 'text/javascript';\n    sensor.src = '/scripts/main.min.js';\n    s.parentNode.insertBefore(sensor, null);\n})();\n```\n\n\u003e Make sure to replace `\u003cPerimeterX App id\u003e` with your PerimeterX application id. You can find this code snippet in the `popup.js` file in this repository.\n\n## Advanced Blocking Response Integration\n\n### What Is Advanced Blocking Response?\n\nIn special cases, (such as XHR post requests) a full Captcha page render might not be an option. In such cases, the Advanced Blocking Response returns a JSON object containing all the information needed to render your own Captcha challenge implementation, be it a popup modal, a section on the page, etc.\nAdvanced Blocking Response occurs when a request that is marked for blocking contains an `Accept` header with the value of `application/json`. It returns a JSON with the following structure:\n\n```json\n{\n    \"appId\": String,\n    \"jsClientSrc\": String,\n    \"firstPartyEnabled\": Boolean,\n    \"vid\": String,\n    \"uuid\": String,\n    \"hostUrl\": String,\n    \"blockScript\": String\n}\n```\n\n### Integration\n\nTo render the challenge element upon receving an Advanced Blocking Response (ABR) follow these steps:\n\n1. In your networking layer, make sure you handle errors and verify the response code received. An ABR will always have the 403 status code. The example in this repository uses `fetch`, and always sends back the status code and body in response to network calls (`networkManager.js` lines 16-19)\n2. Add the following `window` properties:\n\n    ```javascript\n     window._pxAppId = '\u003cappId\u003e'; // PerimeterX's application id\n     window._pxJsClientSrc = '\u003cjsClientSrc\u003e'; // PerimeterX's JavaScript sensor url\n     window._pxFirstPartyEnabled = \u003cfirstPartyEnabled\u003e; // A boolean flag indicating whether first party is enabled or not\n     window._pxVid = '\u003cvid\u003e'; // PerimeterX's visitor id\n     window._pxUuid = '\u003cuuid\u003e'; // PerimeterX's unique user id\n     window._pxHostUrl = '\u003chostUrl\u003e'; // PerimeterX's cloud component URL\n    ```\n\n    \u003e The values for the properties can be found in the ABR object. See `networkManager.js` lines 60-65 for an implementation example.\n\n3. Add an empty `div` element with an `id` attribute of `px-captcha` to the location in the page where the Captcha will be rendered. For example:\n\n    ```javascript\n    const pxDiv = document.createElement('div');\n    pxDiv.id = 'px-captcha';\n    challengeDiv.appendChild(pxDiv);\n    ```\n\n    \u003e `challengeDiv` is the HTML element you want to append the challenge element to.\n\n4. Call the `window.pxRenderHumanChallenge();` global method to render the challenge.\n\n### Challenge Result Callback\n\nOnce a challenge is solved, it will refresh the page by default. If you want to implement your own challenge success logic, use the `_pxOnCaptchaSuccess` callback. The callback can be used as follows:\n\n```javascript\nwindow._pxOnCaptchaSuccess = function (isValid) {\n    if (isValid) {\n        // challenge was solved successfully.\n        // do something here.\n    }\n};\n```\n\n## Optional Configuration\n\n### Challenge Element Langauge\n\nTo set the element's language code, use the `window._pxSelectedLocale = '\u003clanguageCode\u003e';` property.\n\n\u003e A list of supported languages can be found [here](https://docs.perimeterx.com/pxconsole/docs/human-challenge#section-18-n-internationalization-and-localization)\n\n### Customizing the Challenege\n\nTo customize the Human Challenge element, refer to the guide [here](https://docs.perimeterx.com/pxconsole/docs/human-challenge#section-customization)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperimeterx%2Fperimeterx-chrome-extension-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fperimeterx%2Fperimeterx-chrome-extension-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperimeterx%2Fperimeterx-chrome-extension-demo/lists"}