Skip to content

Commit

Permalink
Improvements: Reinstate existing _pxOnCaptchaSuccess (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
omrilotan committed Jun 22, 2021
1 parent f6ddd3f commit 753f257
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# 1.0.3

## Improvements

### Reinstate existing _pxOnCaptchaSuccess
Superimpose existing _pxOnCaptchaSuccess (when applicable) and reinstate the old one when finished

### Allow UI timeout to be Infinity
To disable abort function for long wait

### Ease in challenge appearance (PerimeterX Human Challenge)
Instead of jumping into appearance - add an open animation for the challenge

<details>
<summary>Visual change</summary>

| Before | After
| - | -
| ![](https://user-images.githubusercontent.com/516342/122932879-05102080-d366-11eb-9be0-d841e4fcf695.gif) | ![](https://user-images.githubusercontent.com/516342/122932930-11947900-d366-11eb-9f2d-3eee1c0e8fe1.gif)

</details>

# 1.0.2

## Bug Fixes
Expand Down
9 changes: 9 additions & 0 deletions lib/UIElements/__snapshots__/spec.js.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions lib/UIElements/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ const styles = ({ zIndex = 10000 } = {}) => `
box-shadow: 0 0 2em rgba(0, 0, 0, .4);
padding: 1em 1.5em;
}
@keyframes px-challenge-appear {
0% { max-height: 0px; }
60% { max-height: 0px; }
100% { max-height: 200px; }
}
.${CHALLENGE_BOX_CLASSNAME} > div > iframe {
margin: 0 auto;
animation: px-challenge-appear .6s ease-in;
}
.${MODAL_CLASSNAME} p,
.${MODAL_CLASSNAME} .${CHALLENGE_BOX_CLASSNAME} {
margin: 0 0 .5em;
Expand Down
14 changes: 10 additions & 4 deletions lib/openModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@ module.exports = (
}
);

const _pxOnCaptchaSuccess = window._pxOnCaptchaSuccess;
window._pxOnCaptchaSuccess = function(isValid) {
removeCaptcha();
isValid
? resolve()
: reject(new Error('PerimeterX Axios Interceptor: Failed to exonerate visitor.'))
;
window._pxOnCaptchaSuccess = _pxOnCaptchaSuccess;
return _pxOnCaptchaSuccess && _pxOnCaptchaSuccess.call(window, isValid);
};

const body = document.body || document.getElementsByTagName('body')[0];
Expand Down Expand Up @@ -78,10 +81,13 @@ module.exports = (
* @returns {void}
*/
function recaptchaHandling(script, { base = document, timeout = 3000, reject = () => null } = {}) {
const abort = setTimeout(() => {
removeCaptcha();
reject(new Error(`PerimeterX Axios Interceptor: Failed to load script resource after ${timeout}ms.`));
}, timeout);
const abort = timeout < Infinity
? setTimeout(() => {
removeCaptcha();
reject(new Error(`PerimeterX Axios Interceptor: Failed to load script resource after ${timeout}ms.`));
}, timeout)
: undefined
;

script.addEventListener(
'load',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "perimeterx-axios-interceptor",
"version": "1.0.2",
"version": "1.0.3",
"description": "🧱 Intercept requests which are blocked by PerimeterX - pop up the challenge and retry the request",
"keywords": [
"perimeterx",
Expand Down

0 comments on commit 753f257

Please sign in to comment.