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

Session Cookies not loaded correctly? #31

Closed
dax-classix opened this issue Sep 26, 2016 · 8 comments
Closed

Session Cookies not loaded correctly? #31

dax-classix opened this issue Sep 26, 2016 · 8 comments
Labels

Comments

@dax-classix
Copy link

I'm trying to develop using nodemon, so my node process is restarting frequently. I wanted to use the profile option so I don't need to scan the QR every time it restarts. I am using the sample 7 line script.

I initialize like this:

const profile = 'dax.wechaty.json';
const bot = new Wechaty({ profile });

I get the following errors upon restart:

ERR! PuppetWebBrowser loadSession() addCookies() exception: {"errorMessage":"Can only set Cookies for the current domain","request":{"headers":{"Accept":"application/json; charset=utf-8","Connection":"close","Content-Length":"99","Content-Type":"application/json;charset=UTF-8","Host":"[REDACTED]:65121"},"httpVersion":"1.1","method":"POST","post":"{\"cookie\":{\"name\":\"pgv_si\",\"value\":\"[REDACTED]\",\"path\":\"/\",\"domain\":\".wechat.com\",\"secure\":false}}","url":"/cookie","urlParsed":{"anchor":"","query":"","file":"cookie","directory":"/","path":"/cookie","relative":"/cookie","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/cookie","queryKey":{},"chunks":["cookie"]},"urlOriginal":"/session/[REDACTED]/cookie"}}

[REDACTED] contains the (seemingly) correct session info.

Am I doing something wrong?

@huan
Copy link
Member

huan commented Sep 27, 2016

Hi dax,

your code looks no problem at all.

so I suggest you to:

  1. run npm run demo to have a test with example bot.
    1. npm run demo to start it
    2. it should show login qrcode after a while
    3. scan the qrcode to login
    4. after login, Ctrl+C to stop it.
    5. run npm run demo again, to see if it could login with the lastest session/cookies.
    6. it should work well.(if you are doing the same as what I just did)
  2. otherwise, check the code version you used. What I just tested is the lastest master version.
    1. update by git pull to get the lastest code

If you still have problem, please provide more details here.

@huan
Copy link
Member

huan commented Oct 13, 2016

dax, how about this problem going?

I noticed that the domain name is wechaty.com in your log.

"domain":".wechat.com"

this seems should not happen if you did not change the code. wechaty always use wx.qq.com, which is hard coded. did you change that?

@huan huan added the bug label Oct 17, 2016
@huan
Copy link
Member

huan commented Nov 9, 2016

Now we should also consider the new wx.qq.com domain list, i.e.:

  1. wx2.qq.com
  2. wx8.qq.com

Before we load cookie, maybe we should check the current domain name first: If the current domain name is different to the saved, for example: wx.qq.com in saved cookies but the current domain is wx2.qq.com, then we save cookies to the current domain wx2.qq.com to prevent add cookie failure.

@huan
Copy link
Member

huan commented Dec 3, 2016

WARN PuppetWebBrowserCookie addCookies() exception: invalid cookie domain: invalid domain:".wx2.qq.com"
  (Session info: chrome=53.0.2785.92)
  (Driver info: chromedriver=2.22 (5e2d5494d735a71aa5c2e7ef9bf5ce96945e92e9),platform=Linux 3.16.0-4-amd64 x86_64)
ERR PuppetWebBrowserCookie load() add() exception: invalid cookie domain: invalid domain:".wx2.qq.com"
  (Session info: chrome=53.0.2785.92)
  (Driver info: chromedriver=2.22 (5e2d5494d735a71aa5c2e7ef9bf5ce96945e92e9),platform=Linux 3.16.0-4-amd64 x86_64)

@dcsan
Copy link

dcsan commented Dec 11, 2016

I was also seeing this issue, when trying to extract the minimum files needed to run my own bot.

WARN PuppetWebBrowserCookie addCookies() exception: invalid cookie domain: invalid domain:".wechat.com"
  (Session info: chrome=54.0.2840.98)
  (Driver info: chromedriver=2.25.426935 (820a95b0b81d33e42712f9198c215f703412e1a1),platform=Mac OS X 10.12.1 x86_64)
ERR PuppetWebBrowserCookie load() add() exception: invalid cookie domain: invalid domain:".wechat.com"
  (Session info: chrome=54.0.2840.98)
  (Driver info: chromedriver=2.25.426935 (820a95b0b81d33e42712f9198c215f703412e1a1),platform=Mac OS X 10.12.1 x86_64)

Wechaty Doctor

  1. Wechaty version: #git[40f47f0 0.6.47]
  2. Darwin x64 version 16.1.0 memory 23/8192 MB
  3. Docker: false
  4. Node version: v7.2.1

This is using the ding-dong example

it seems fixed in wechaty 0.6.52

Wechaty Doctor

  1. Wechaty version: #git[4543b8f 0.6.52]
  2. Darwin x64 version 16.1.0 memory 230/8192 MB
  3. Docker: false
  4. Node version: v7.2.1

@dcsan
Copy link

dcsan commented Dec 11, 2016

i still get this error sometimes but doesnt' seem to prevent logging in.
I think it's related to chrome leaving ghost processes running after exit

@huan
Copy link
Member

huan commented Dec 12, 2016

@dcsan I'm planning to add a method like PuppetWeb.hostname() to return the current webwxApp domain, then add the cookie to the right domain name to prevent this error.

And according to your log, we need to notice the wechat domain for out of China: .wechat.com as well.

Also, this method is needed by #121

huan added a commit that referenced this issue Dec 13, 2016
@huan
Copy link
Member

huan commented Dec 13, 2016

@dcsan @dax-classix the latest code will get hostname from cookie, then use hostname as the wechat web url.

So this issue should be fixed by this commit.

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

No branches or pull requests

3 participants