bertrandom / chrome-cookies-secure

Extract encrypted Google Chrome cookies for a url on a Mac or Linux
https://www.npmjs.com/package/chrome-cookies-secure
MIT License
142 stars 51 forks source link

fail: unable to open database file #20

Open lonecrane opened 4 years ago

lonecrane commented 4 years ago

Hi everyone. The profile for test has been checked by manually opening chrome, but the code provided by readme.md keeps issuing the error 'unable to open database file'. I am on windows 10 x64, chrome 80.0.3987.149 (Official Build) (64-bit) (cohort: 80_149_Win), Node v12.16.1, and npm 6.13.4. Here is the code for test:

const chrome = require('chrome-cookies-secure');
const puppeteer = require('puppeteer-core');

const url = 'https://www.hostloc.com/forum.php';

const getCookies = (callback) => {
    chrome.getCookies(url, 'puppeteer', function(err, cookies) {
        if (err) {
            console.log(err, 'error');
            return
        }
        console.log(cookies, 'cookies');
        callback(cookies);
    }, 
    './UserData2')  // Absolute path has been also tested.
}

getCookies(async (cookies) => {
    const browser = await puppeteer.launch({ 
        headless: false
    });
    const page = await browser.newPage();

    await page.setCookie(...cookies);
    await page.goto(url);
    await page.waitFor(1000);
    browser.close();
});

The errors issued:

events.js:288
      throw er; // Unhandled 'error' event
      ^
[Error: SQLITE_CANTOPEN: unable to open database file
Emitted 'error' event on Database instance at:
] {
  errno: 14,
  code: 'SQLITE_CANTOPEN'
}
ZekeSnider commented 4 years ago

From my understanding that parameter only accepts a profile name, not a path. https://github.com/bertrandom/chrome-cookies-secure/blob/master/index.js#L255

Have you tried with the profile name? You can verify if the directory exists by checking the page referenced in that code (dependent on your OS).

lonecrane commented 4 years ago

@ZekeSnider Thaks a lot. With your help, I have figured out this issue. The 'profile' parameter should be a word such as 'Default', neither absolute path nor relative path. It's designed that only the parent folder of the file 'Cookies' can be changed because chrome-cookies-secure currently assembles the target path as

path = os.homedir() + `\\AppData\\Local\\Google\\Chrome\\User Data\\${profile}\\Cookies`

By the way, it seems that chrome-cookies-secure can't deal with the cookies generated by Chome 80.0.3987.149 (Official Build) (64-bit) (cohort: Stable) on windows 10. The web page opened by chrome-cookies-secure show that I am not logged in, and the obtained cookies are not the ones shown by Edit-this-cookie.

rubengmurray commented 4 years ago

Hi @lonecrane,

Yes that parameter is designed to just be the name of the profile to be used. When I added this functionality the package was only designed to be used on mac / linux so I'm not sure if there are now complications with this method on Windows.

I can add a further note to the example to make it clearer - looks like it would have saved you some time.

Have you managed to get it working at all with your current setup?

lonecrane commented 4 years ago

@rubengmurray Hi. At present I am using the demo code which use the 'require' method. I am totally newbie to node.js, so I wander how to use the index.js directly if I modify this file.

rubengmurray commented 4 years ago

If you're looking to work on changes locally to chrome-cookies-secure there are two ways.

1) You can test changes quickly by modifying the code of chrome-cookies-secure directly within node_modules of your project and try and start your app. It'll use the modified code as long as you don't run an npm install at any point after your changes (it's risky because you may forget at some point and lose everything you've done).

2) Fork this repo, pull it down locally and then use npm link. (https://docs.npmjs.com/cli/link.html.) Run npm link from the root of the chrome-cookies-secure folder and then within your own repo run npm link chrome-cookies-secure. npm will use your local version of chrome-cookies-secure. A subsequent npm install will still break the link here, but you won't lose any of your changes (you'll need to run npm link chrome-cookies-secure after every npm install).

lonecrane commented 4 years ago

@rubengmurray Thanks a lot. You are so nice. With the the default parameter of profile path, I have tested my current Chrome 80.0.3987.149 (Official Build) (64-bit) (cohort: Stable) on windows 10. However, it seems that chrome-cookies-secure can't decrypt the cookies managed by this chrome version. After running the above test script, the web page opened by chrome-cookies-secure shows that I am not logged in, and the displayed cookies are not the ones viewed by Edit-this-cookie.

rubengmurray commented 4 years ago

I think this functionality was only added recently. Are you running the latest version of chrome-cookies-secure? See https://github.com/bertrandom/chrome-cookies-secure/pull/19

It may be worth dropping a comment in that PR or tagging the guy that added that functionality.

I'm on macOS so I probably won't be as useful as the author of that PR. Looks like it was designed to specifically handle your issue?

lonecrane commented 4 years ago

@rubengmurray Many thanks. I just installed chrome-cookies-secure two or three days ago. Maybe my problem arise from my another misunderstanding, and I would like to have more deeper test, modifying index.js to let chrome stay running and then checking whether the actual profile is correct. As I am not a programmer, report further may come in several days.

oliver-gomes commented 3 years ago

Any update guys? I am having the same exact issues and using Windows 10 with Chrome 86.0.4240.193 (Official Build) (64-bit). My profile is set to the "Default" folder which is the parent of Cookies file. Any help appreciated @lonecrane @rubengmurray

rubengmurray commented 3 years ago

Hi @oliver-gomes,

I'm afraid I can't help out with Windows issues as I'm Mac only. I'd suggest looking at PR #19 , specifically the new if blocks added. Perhaps try the version of chrome-cookies-secure pre #19 too and see if you experience the same issues?

You may need to debug the issue locally by using npm link as I described above and putting some logs in there to see if you can verify what's going on.

The path in that PR is hard-coded to a windows directory, it's probably a common dir but it could be an issue (I have no way of even starting to debug myself).

oliver-gomes commented 3 years ago

@rubengmurray thanks for pointing me to the PR and yes I am using the latest version which have #19 implemented. I am still getting the same issue. Since windows giving me problems I will try it on mac, Thanks!

suntong commented 3 years ago

I'm having exactly same problem. Anybody have made it work under Linux?

rubengmurray commented 3 years ago

I'm afraid I don't have any way of testing this on Linux

suntong commented 3 years ago

Thanks for your reply Reece. It's OK. I got it working, but from https://github.com/paragbaxi/chrome-cookies-secure.

BTW, I got here following your blog, https://dev.to/rubengmurray/using-cookies-puppeteer-nodejs-to-mirror-a-chrome-profile-on-macos-1l6m, Thanks for that Reece.

rubengmurray commented 3 years ago

Thanks for your comment. I'd be up for re-upping to npm as another package providing the license is set correctly. Might be able to look into this week.

rubengmurray commented 3 weeks ago

@suntong are you still using the fork at https://github.com/paragbaxi/chrome-cookies-secure?

I'm stumped why that fork would work and this package wouldn't as the runtime diff changes don't seem to touch anything in the area

https://github.com/bertrandom/chrome-cookies-secure/compare/master...paragbaxi:chrome-cookies-secure:master

suntong commented 3 weeks ago

Maybe because of this (https://github.com/bertrandom/chrome-cookies-secure/commit/23295e9e21354f6fa06c370665f42fa9c8cca97e) @rubengmurray ?

Sorry I haven't touch it since then.

rubengmurray commented 2 weeks ago

@suntong that just looks like the promise wrapper and readme update which is something that is available in this repo (in fact was added here by myself originally).

~Are you still using this and can give it a go? Would mean we can close this issue.~

Given you are no longer using do you mind if I close this issue?

suntong commented 2 weeks ago

Sure, go ahead.

I'm not the original author either.