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

fail: unable to open database file #20

Open
lonecrane opened this issue Mar 19, 2020 · 19 comments
Open

fail: unable to open database file #20

lonecrane opened this issue Mar 19, 2020 · 19 comments

Comments

@lonecrane
Copy link

lonecrane commented Mar 19, 2020

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
Copy link

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
Copy link
Author

lonecrane commented Mar 22, 2020

@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
Copy link
Collaborator

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
Copy link
Author

@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
Copy link
Collaborator

rubengmurray commented Mar 22, 2020

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
Copy link
Author

lonecrane commented Mar 22, 2020

@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
Copy link
Collaborator

I think this functionality was only added recently. Are you running the latest version of chrome-cookies-secure? See #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
Copy link
Author

@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
Copy link

oliver-gomes commented Nov 16, 2020

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
Copy link
Collaborator

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
Copy link

@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
Copy link

suntong commented Mar 20, 2021

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

@rubengmurray
Copy link
Collaborator

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

@suntong
Copy link

suntong commented Mar 22, 2021

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
Copy link
Collaborator

rubengmurray commented Mar 22, 2021

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
Copy link
Collaborator

@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

master...paragbaxi:chrome-cookies-secure:master

@suntong
Copy link

suntong commented Jul 1, 2024

Maybe because of this (23295e9) @rubengmurray ?

Sorry I haven't touch it since then.

@rubengmurray
Copy link
Collaborator

rubengmurray commented Jul 3, 2024

@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
Copy link

suntong commented Jul 4, 2024

Sure, go ahead.

I'm not the original author either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants