frame-tested-evaluate.js 760 B

12345678910111213141516171819202122232425262728
  1. import { respondable } from '../../core/utils';
  2. function frameTestedEvaluate(node, options) {
  3. const resolve = this.async();
  4. const { isViolation, timeout } = Object.assign(
  5. { isViolation: false, timeout: 500 },
  6. options
  7. );
  8. // give the frame .5s to respond to 'axe.ping', else log failed response
  9. let timer = setTimeout(() => {
  10. // This double timeout is important for allowing iframes to respond
  11. // DO NOT REMOVE
  12. timer = setTimeout(() => {
  13. timer = null;
  14. resolve(isViolation ? false : undefined);
  15. }, 0);
  16. }, timeout);
  17. respondable(node.contentWindow, 'axe.ping', null, undefined, () => {
  18. if (timer !== null) {
  19. clearTimeout(timer);
  20. resolve(true);
  21. }
  22. });
  23. }
  24. export default frameTestedEvaluate;