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.

[BUG] jpeg-js - Error: maxMemoryUsageInMB limit exceeded

See original GitHub issue

Context:

  • Playwright Version: 1.22
  • Operating System: Mac with Docker
  • Node.js version: 14.19
  • Browser: All
  • Extra: We are using Playwright for Visual Regression

Code Snippet

Running command:

docker run --rm --network=host --ipc=host -v $(pwd):/work/ mcr.microsoft.com/playwright:v1.22.0-focal bash -c 'cd work && npx playwright install && npx playwright test --update-snapshots'

playwright.config.ts

/* eslint-disable no-console */
import type { PlaywrightTestConfig } from '@playwright/test';
import { devices } from '@playwright/test';

/**
 * Read environment variables from file.
 * https://github.com/motdotla/dotenv
 */
// require('dotenv').config();

const port = global.process.env.PORT ? parseInt(global.process.env.PORT, 10) : 4200;
const url = `http://localhost:${port}`;

/**
 * See https://playwright.dev/docs/test-configuration.
 */
const config: PlaywrightTestConfig = {
  testDir: './tests',
  /* Maximum time one test can run for. */
  timeout: 100000,
  expect: {
    /**
     * Maximum time expect() should wait for the condition to be met.
     * For example in `await expect(locator).toHaveText();`
     */
    timeout: 100000,
  },
  /* Fail the build on CI if you accidentally left test.only in the source code. */
  forbidOnly: !!process.env.CI,
  /* Retry on CI only */
  retries: process.env.CI ? 2 : 0,
  /* Opt out of parallel tests on CI. */
  workers: process.env.CI ? 1 : undefined,
  /* Reporter to use. See https://playwright.dev/docs/test-reporters */
  reporter: [['line'], ['html']],
  /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
  use: {
    /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
    actionTimeout: 0,
    /* Base URL to use in actions like `await page.goto('/')`. */
    baseURL: url,

    /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
    trace: 'on-first-retry',
  },

  /* Configure projects for major browsers */
  projects: [
    {
      name: 'chromium',
      use: {
        ...devices['Desktop Chrome'],
      },
    },

    {
      name: 'firefox',
      use: {
        ...devices['Desktop Firefox'],
      },
    },

    {
      name: 'webkit',
      use: {
        ...devices['Desktop Safari'],
      },
    },
    {
      name: 'Mobile Chrome Portrait',
      use: {
        ...devices['Pixel 5'],
      },
    },
    {
      name: 'Mobile Safari Portrait',
      use: {
        ...devices['iPhone 12'],
      },
    },
    {
      name: 'Tablet Safari Portrait',
      use: {
        ...devices['iPad (gen 7)'],
      },
    },
  ],

  /* Folder for test artifacts such as screenshots, videos, traces, etc. */
  // outputDir: 'test-results/',
  webServer: {
    command: `yarn start --port ${port}`,
    url,
    timeout: 300000,
  },
  /* Run your local dev server before starting the tests */
};

export default config;

urls.ts

/* eslint-disable sonarjs/no-duplicate-string */
interface PlaywrightUrl {
  url: string;
  pageName: string;
  mask?: string[];
}

export const URLS: PlaywrightUrl[] = [
  {
    url: '/sign/in',
    pageName: 'sign-in',
  },
  {
    url: '/contact',
    pageName: 'contact',
  },
  {
    url: '/faq',
    pageName: 'faq',
    mask: ['app-faq-items'],
  },
  {
    url: '/dashboard?login-token=token-demo',
    pageName: 'dashboard',
    mask: ['.layout__main-content'],
  },
  {
    url: '/services/wizbii-drive/lessons?login-token=token-demo',
    pageName: 'wizbii-drive-lessons',
  },
  {
    url: '/services/wizbii-drive/series?login-token=token-demo',
    pageName: 'wizbii-drive-series',
    mask: ['.serie__action', '.serie__status'],
  },
  {
    url: '/services/wizbii-drive/series?mode=training&login-token=token-demo',
    pageName: 'wizbii-drive-series-training',
    mask: ['.serie__action', '.serie__status'],
  },
  {
    url: '/services/wizbii-drive/series?group-by=thematics&login-token=token-demo',
    pageName: 'wizbii-drive-thematics',
  },
  {
    url: '/services/wizbii-drive/series/thematics/l_legales?login-token=token-demo',
    pageName: 'wizbii-drive-series-theme',
    mask: ['.serie__action', '.serie__status'],
  },
  {
    url: '/services/wizbii-drive/series/thematics/l_legales?mode=training&login-token=token-demo',
    pageName: 'wizbii-drive-series-theme-training',
    mask: ['.serie__action', '.serie__status'],
  },
  {
    url: '/services/wizbii-drive/progress?login-token=token-demo',
    pageName: 'wizbii-drive-progress',
    mask: ['.serie__action', '.serie__status', '.graph-section'],
  },
  {
    url: '/services/wizbii-drive/advices?login-token=token-demo',
    pageName: 'wizbii-drive-advices',
    mask: ['drive-advice-list-item'],
  },
  {
    url: '/services/wizbii-blog?login-token=token-demo',
    pageName: 'wizbii-blog-list',
    mask: ['app-article-item'],
  },
  {
    url: '/services/wizbii-blog?category=entrepreneuriat&login-token=token-demo',
    pageName: 'wizbii-blog-list-category',
    mask: ['app-article-item'],
  },
];

visual-testing.spec.ts

import { expect, test } from '@playwright/test';
import { URLS } from './urls';

test.describe.configure({ mode: 'parallel' });

URLS.forEach(({ url, pageName, mask }) => {
  test(`${pageName}`, async ({ page }) => {
    await page.goto(url);
    await page.waitForTimeout(5000);
    expect(
      await page.screenshot({
        fullPage: true,
        type: 'jpeg',
        quality: 50,
        ...(mask && mask.length > 0 ? { mask: mask.map((m) => page.locator(m)) } : {}),
      })
    ).toMatchSnapshot(`${pageName}.jpeg`, {
      threshold: 0.4,
    });
  });
});

Describe the bug

When I’m running the command to update the local screenshots, i have this error on some pages

Error: maxMemoryUsageInMB limit exceeded by at least 6MB

I’m guessing it’s from jpeg-js but i don’t know how to increase the memory limit to not have this bug 😕

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rwollcommented, May 19, 2022

I confirmed this is coming from jpeg-js which has a default of 512 MB. Playwright does not expose anything to configure this at the moment.

As a potential workaround, can you try setting the scale option of screenshot to css?

0reactions
squelixcommented, Jun 9, 2022

I would like to use png but png pictures are too heavy in a repository 😕

Were you able to try scale: "css", and did it help with your image size? See https://playwright.dev/docs/api/class-page#page-screenshot-option-scale for notes

I used scale: "css" but it was not very useful for the image size 😕

Read more comments on GitHub >

github_iconTop Results From Across the Web

maxMemoryUsageInMB limit exceeded - Backendless Support
When calling one of my API Services, I'm getting the following error: 668 Error: maxMemoryUsageInMB limit exceeded by at least 24MB.
Read more >
Error in train command in ZapWorks CLI - Bug Reports
throw new Error( maxMemoryUsageInMB limit exceeded by at least ... @zappar\zapworks-cli\node_modules\jpeg-js\lib\decoder.js:1051:13)
Read more >
jimp - Bountysource
Expected Behavior. Jimp.read promise should be rejected in case of errors. ... Error: maxMemoryUsageInMB limit exceeded by at least 226MB.
Read more >
jpeg-js - npm
A pure javascript JPEG encoder and decoder. Latest version: 0.4.4, last published: 7 months ago. Start using jpeg-js in your project by ...
Read more >
Nodejs memory gets filled too quick when uploading images
The part of reading the file, i.e. Jimp.read('filename') has caused the memory problem. It's a known bug as seen here: ...
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