{"id":22096078,"url":"https://github.com/perimeterx/perimeterx-abr-samples","last_synced_at":"2025-04-09T23:10:15.960Z","repository":{"id":70060530,"uuid":"196208202","full_name":"PerimeterX/perimeterx-abr-samples","owner":"PerimeterX","description":"Samples for the Advanced Blocking Response feature","archived":false,"fork":false,"pushed_at":"2020-04-16T18:16:17.000Z","size":219,"stargazers_count":4,"open_issues_count":0,"forks_count":4,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-24T00:55:35.388Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"HTML","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":"2019-07-10T13:14:26.000Z","updated_at":"2024-02-19T18:15:59.000Z","dependencies_parsed_at":"2023-04-06T12:11:16.941Z","dependency_job_id":null,"html_url":"https://github.com/PerimeterX/perimeterx-abr-samples","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerimeterX%2Fperimeterx-abr-samples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerimeterX%2Fperimeterx-abr-samples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerimeterX%2Fperimeterx-abr-samples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerimeterX%2Fperimeterx-abr-samples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PerimeterX","download_url":"https://codeload.github.com/PerimeterX/perimeterx-abr-samples/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248125613,"owners_count":21051770,"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","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:38.055Z","updated_at":"2025-04-09T23:10:15.931Z","avatar_url":"https://github.com/PerimeterX.png","language":"HTML","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) Advanced Blocking Response Examples\n\n\u003e This folder contains examples of how to implement Advanced Blocking Response.\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, using the Advanced Blocking Response returns a JSON object continaing all the information needed to render your own Captcha challenge implementation, be it a popup modal, a section on the page, etc.\n\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```javascript\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## Minimum Requirements\n\nTo render the challenege element (be it Human Challenge or reCaptcha) you must have the following elements/snippets in your implementation:\n\n### The Window Object Properties\n\nThe element that renders the challenge must contain the following `window` object properties:\n\n```javascript\n\u003cscript\u003e\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 wether 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\u003c/script\u003e\n```\n\nAll of these properties should be taken from the Advanced Blocking Response JSON response.\n\n### The Challenge Element\n\nThe challenge element will render to a `div` with an id of `px-captcha`:\n\n```html\n\u003cdiv id=\"px-captcha\"\u003e\u003c/div\u003e\n```\n\n### Loading the Block Script\n\nAdd the block script to rendering element either by a `script` tag or by dynamically loading it to the Head element:\n\n```javascript\nlet script = document.createElement('script');\nscript.src = response.blockScript; // use the blockScript property from the Advanced Blocking Response result.\ndocument.getElementsByTagName('head')[0].appendChild(script);\n```\n\n## Challenge Result Callback\n\nYou can add the `_pxOnCaptchaSuccess` callback function on the `window` object of your challenge page to react according to the challenge status. For example when using a modal, you can use this callback to close the modal once the challenge is successfullt solved.\n\nThe `_pxOnCaptchaSuccess` callback can be used as follows:\n\n```javascript\n   window._pxOnCaptchaSuccess = function(isValid) {\n       if (isValid) {\n           alert(\"Challenge Successful\");\n       } else {\n           alert(\"Challenge Failed\");\n       }\n   }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperimeterx%2Fperimeterx-abr-samples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fperimeterx%2Fperimeterx-abr-samples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperimeterx%2Fperimeterx-abr-samples/lists"}