Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Headless can't read indexedDB written from Headful and vice versa #1270

Closed
vsemozhetbyt opened this issue Nov 3, 2017 · 6 comments
Closed
Labels
bug chromium Issues with Puppeteer-Chromium unconfirmed

Comments

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Nov 3, 2017

I am not sure if I use indexedDB completely properly, please, correct me if needed.

Code example:
'use strict';

const puppeteer = require('puppeteer');

(async function main() {
  try {
    let browser = await puppeteer.launch({
      headless: false,
      userDataDir: 'test-profile-dir',
    });
    let page = await browser.newPage();
    await page.goto('https://example.org/');
    await page.evaluate(setIDB, 'headfulIDB', 'foo');
    await page.close();
    await browser.close();

    browser = await puppeteer.launch({
      headless: true,
      userDataDir: 'test-profile-dir',
    });
    page = await browser.newPage();
    await page.goto('https://example.org/');
    await page.evaluate(setIDB, 'headlessIDB', 'bar');
    await page.close();
    await browser.close();

    browser = await puppeteer.launch({
      headless: false,
      userDataDir: 'test-profile-dir',
    });
    page = await browser.newPage();
    await page.goto('https://example.org/');
    console.log('Headful mode.');
    console.log('Headful IDB: ', await page.evaluate(getIDB, 'headfulIDB'));
    console.log('Headless IDB: ', await page.evaluate(getIDB, 'headlessIDB'));
    await page.close();
    await browser.close();

    browser = await puppeteer.launch({
      headless: true,
      userDataDir: 'test-profile-dir',
    });
    page = await browser.newPage();
    await page.goto('https://example.org/');
    console.log('Headless mode.');
    console.log('Headful IDB: ', await page.evaluate(getIDB, 'headfulIDB'));
    console.log('Headless IDB: ', await page.evaluate(getIDB, 'headlessIDB'));
    await page.close();
    await browser.close();
  } catch (err) {
    console.error(err);
  }
})();


function setIDB(key, value) {
  return new Promise((resolve, reject) => {
    const openRequest = indexedDB.open('testIDB', 1);

    openRequest.onerror = (err) => { reject(err.target.error); };
    openRequest.onupgradeneeded = (event) => { event.target.result.createObjectStore('test'); };

    openRequest.onsuccess = (event) => {
      const db = event.target.result;

      db.onerror = (err) => { db.close(); reject(err.target.error); };

      db.transaction('test', 'readwrite')
        .objectStore('test')
        .put(value, key)
        .onsuccess = () => { db.close(); resolve(); };
    };
  });
}

function getIDB(key) {
  return new Promise((resolve, reject) => {
    const openRequest = indexedDB.open('testIDB', 1);

    openRequest.onerror = (err) => { reject(err.target.error); };
    openRequest.onupgradeneeded = (event) => { event.target.result.createObjectStore('test'); };

    openRequest.onsuccess = (event) => {
      const db = event.target.result;

      db.onerror = (err) => { db.close(); reject(err.target.error); };

      db.transaction('test', 'readonly')
        .objectStore('test')
        .get(key)
        .onsuccess = (eventGet) => {
          const { result } = eventGet.target;
          db.close();
          resolve(result);
        };
    };
  });
}

Output:
Headful mode.
Headful IDB:  foo
Headless IDB:  undefined
Headless mode.
Headful IDB:  undefined
Headless IDB:  bar

@vsemozhetbyt
Copy link
Contributor Author

Refs:
#921
#1268

@bean5
Copy link

bean5 commented Mar 29, 2018

Assuming I have this same issue (sure smells like it), this also occurs in headfull if you manually set --user-data-dir=/tmp/someFolder/. This might be a different case, though. It appears that if I update indexedDB while in headfull, close, then reopen in headfull, the changes did not persist (so headfull can't read headfull). Same thing happens between the other permutations of pairings: headless - headless, and headless - headful, headful - headless.

This happens for puppeteer -- not for actual usage.

@aslushnikov aslushnikov added the chromium Issues with Puppeteer-Chromium label Dec 6, 2018
@hmmhmmhm
Copy link

hmmhmmhm commented Jun 3, 2019

Hi, this article seems to have been written a year ago, but I've just experienced this error, and as a result I found the answer. In my case, it happened because I tried to execute the command on page 'about:blank'

@stale
Copy link

stale bot commented Jun 27, 2022

We're marking this issue as unconfirmed because it has not had recent activity and we weren't able to confirm it yet. It will be closed if no further activity occurs within the next 30 days.

@stale stale bot added the unconfirmed label Jun 27, 2022
@stale
Copy link

stale bot commented Jul 27, 2022

We are closing this issue. If the issue still persists in the latest version of Puppeteer, please reopen the issue and update the description. We will try our best to accomodate it!

@stale stale bot closed this as completed Jul 27, 2022
@riyadshauk
Copy link

I'm still running into an error where I launch chrome in debug mode with the userDataDir specified, I log in, etc, and connect to it via Pupeteer with the userDataDir specified. My script works. When I try using Puppeteer with headless and the userDataDir, it treats it like a new browser, and requires me to log in to the website I needed to automate on.

to run Chrome, I use this

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222 --no-first-run --no-default-browser-check --user-data-dir=~/chrome-remote_data_dir

To run headful, I reference the generated WS URL in my Puppeteer script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug chromium Issues with Puppeteer-Chromium unconfirmed
Projects
None yet
Development

No branches or pull requests

5 participants