-
-
Notifications
You must be signed in to change notification settings - Fork 416
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
fix: cookies regression: send Page commands for cookies handling #1534
Conversation
let script = 'return document.cookie'; | ||
let jsCookies = await this.executeAtom('execute_script', [script, []]); | ||
// get the cookies from the remote debugger, or an empty object | ||
const cookies = await this.remote.getCookies() || {cookies: []}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what remote.getCookies()
returns if no cookies found?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{"cookies":[]}
in my test, but not sure if it has a case that could return null for example since I haven't tested old versions.
This PR is from the previous deleted code as-is not to change anything right now. (Refactoring would be a separate PR)
for (let [name, value] of _.toPairs(cookieUtils.createJWPCookie(undefined, jsCookies))) { | ||
cookies.push({name, value}); | ||
// the value is URI encoded, so decode it safely | ||
const decodedCookieValues = cookies.cookies.map((cookie) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume we could destruct the object above, like const {cookies} =....
}); | ||
|
||
// zip cookies with decoded value, removing undefined cookie values | ||
return _.zip(cookies.cookies, decodedCookieValues) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we may decode and return in a single chain. I don't see a need for the intermediate decodedCookieValues
variable
let cookies = await this.getCookies(); | ||
if (_.indexOf(_.map(cookies, 'name'), cookieName) === -1) { | ||
const cookies = await this.getCookies(); | ||
const cookie = cookies.find((cookie) => cookie.name === cookieName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be cookies.find(({name}) => name === cookieName)
if (_.indexOf(_.map(cookies, 'name'), cookieName) === -1) { | ||
const cookies = await this.getCookies(); | ||
const cookie = cookies.find((cookie) => cookie.name === cookieName); | ||
if (!cookie) { | ||
this.log.debug(`Cookie '${cookieName}' not found. Ignoring.`); | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be always return true?
} | ||
const cookies = await this.getCookies(); | ||
for (const cookie of cookies) { | ||
await this._deleteCookie(cookie); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may we use B.all
here to speed up the process?
} | ||
const cookies = await this.getCookies(); | ||
for (const cookie of cookies) { | ||
await this._deleteCookie(cookie); | ||
} | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we always return true?
I'll do refactoring (for comments as well) in #1538 as a followup pr |
@KazuCocoa I don't understand if this PR is a verbatim revert of a previous changeset, and if so, which one? |
This is for #1484 (comment). Cookies handling except for setCookies is via remote debugger's I have checked the commit history as well, then noticed maybe something regression potentially happened in appium-ios-driver migration after Appium 1.22.3 if your debugging the mixin resolved wrongly. (I mean |
let me tweak the review in #1538 and merge this to keep the module behavior via Page command at this time |
## [4.21.3](v4.21.2...v4.21.3) (2023-04-01) ### Bug Fixes * cookies regression: send Page commands for cookies handling ([#1534](#1534)) ([908ed1a](908ed1a))
🎉 This PR is included in version 4.21.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
@KazuCocoa The |
Oh, i see. should be void. I'll update it in #1538 |
Using
this.remote
for cookies handling (except for setCookies) is current intentional behavior instead of JavaScript call. (https://gist.github.com/KazuCocoa/b935fbca6efa1abf4688cc94bc14366a for reference)#1532
This change will send
_rpc_forwardSocketData
withPage.
commands.After setting cookies once with
driver.manage.add_cookie(name: "key", value: "value")