question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error during screenshot capture: RangeError: Index out of range | The value of "offset" is out of range.

See original GitHub issue

Current behavior:

Executing cy.screenshot() on large pages causes error. Stack trace:

     RangeError: Index out of range
      at checkInt (buffer.js:1180:11)
      at Buffer.writeUInt32BE (buffer.js:1271:5)
      at new Jimp (/Users/rbayliss/Library/Caches/Cypress/3.0.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/jimp/index.js:137:30)
      at stitchScreenshots (/Users/rbayliss/Library/Caches/Cypress/3.0.1/Cypress.app/Contents/Resources/app/packages/server/lib/screenshots.js:199:17)
      at /Users/rbayliss/Library/Caches/Cypress/3.0.1/Cypress.app/Contents/Resources/app/packages/server/lib/screenshots.js:295:21
      at tryCatcher (/Users/rbayliss/Library/Caches/Cypress/3.0.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/util.js:16:23)
      at Promise._settlePromiseFromHandler (/Users/rbayliss/Library/Caches/Cypress/3.0.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/promise.js:510:31)
      at Promise._settlePromise (/Users/rbayliss/Library/Caches/Cypress/3.0.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/promise.js:567:18)
      at Promise._settlePromise0 (/Users/rbayliss/Library/Caches/Cypress/3.0.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/promise.js:612:10)
      at Promise._settlePromises (/Users/rbayliss/Library/Caches/Cypress/3.0.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/promise.js:691:18)
      at Async._drainQueue (/Users/rbayliss/Library/Caches/Cypress/3.0.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/async.js:133:16)
      at Async._drainQueues (/Users/rbayliss/Library/Caches/Cypress/3.0.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/async.js:143:10)
      at Immediate.Async.drainQueues (/Users/rbayliss/Library/Caches/Cypress/3.0.1/Cypress.app/Contents/Resources/app/packages/server/node_modules/bluebird/js/release/async.js:17:14)
      at runCallback (timers.js:781:20)
      at tryOnImmediate (timers.js:743:5)
      at processImmediate [as _immediateCallback] (timers.js:714:5)

Desired behavior:

Screenshots are captured.

Steps to reproduce:

Call cy.screenshot() on a page that exceeds 16,000,000 square pixels (in my case, the element is 1195px by 13518px). Reproduction test case: https://github.com/rbayliss/cypress-test-tiny/tree/index_error

Versions

Cypress package version: 3.0.1
Cypress binary version: 3.0.1
Chrome 67.0.3396.87 on OSX 10.13

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:14
  • Comments:38 (7 by maintainers)

github_iconTop GitHub Comments

5reactions
vivekbwajcommented, Oct 29, 2020

is there any update on this issue?

4reactions
aleksandryackovlevcommented, Nov 30, 2020

In my case this error was caused by the behavior of the dom.getElementPositioning (https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/dom/coordinates.js#L27). In some cases it returns negative values between -1 and 0 in fromElViewport.top for elements that are being captured.

I suppose changing https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cy/commands/screenshot.js#L235 to y: Math.max(0, elPosition.fromElViewport.top), will fix the problem with negative offsets.

Unfortunatelly, I’m not deeply familiar with the code of cypress, so I can’t predict whether any other behavior of the system will be affected or not by this change.

Can anyone tell me where else this code is used? And is this the right place in code to fix the problem?

For now I just overwrote the screenshot command as a workaround and it works for me:

Cypress.Commands.overwrite(
  'screenshot',
  (originalFn, subject, name, options) => {
    if (subject) {
      let scrollY = null;
      const win = Cypress.dom.getWindowByElement(subject[0]);

      return originalFn(subject, name, {
        ...options,
        onBeforeScreenshot(...args) {
          if (options.onBeforeScreenshot) {
            options.onBeforeScreenshot(...args);
          }

          scrollY = Object.getOwnPropertyDescriptor(win, 'scrollY');

          Cypress.log({
            name: 'stub scrollY',
            displayName: 'stub sY',
            message: `${win.scrollY} => ${
              win.scrollY ? win.scrollY - 1 : win.scrollY
            }`,
          });

          Object.defineProperty(win, 'scrollY', {
            value: win.scrollY ? win.scrollY - 1 : win.scrollY,
          });
        },
        onAfterScreenshot(...args) {
          Object.defineProperty(win, 'scrollY', scrollY);

          if (options.onAfterScreenshot) {
            options.onAfterScreenshot(...args);
          }

          Cypress.log({
            name: 'restore scrollY',
            displayName: 'restore sY',
            message: `${win.scrollY}`,
          });
        },
      });
    }

    return originalFn(subject, name, options);
  }
);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Range offset error when taking screenshot - cypress
I try to take a screenshot with:
Read more >
Python IndexError: List Index Out of Range [Easy Fix] - Finxter
Key Points: To solve the “IndexError: list index out of range”, avoid do not access a non-existing list index.
Read more >
index out of range - WaveMetrics
I am trying to modify a code for normalisation in igor 7. This code works was originally written in Igor4 and works fine...
Read more >
Troubleshooting DBCC error 2570 in SQL Server 2005 and ...
Describes an issue where you receive DBCC Error 2570 when you use the DATA_PURITY ... Invalid or out-of-range data may have been stored...
Read more >
DBDOC Online Help
Summary: GMCL provides DBDOC - a powerful documentation and support tool with live data monitoring for ABB INFI90 distributed process control systems.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found