Skip to content

Conversation

@JPedroBorges
Copy link
Member

@JPedroBorges JPedroBorges commented Aug 25, 2023

Add domain field when creating a new cookie item.

Important

GET

If there are multiples match to a key, it will select based on the order that the browser sent it.
This is not a new behavior, but would be interesting to figure out how is the order affected.

SET

Retrieves information about a single cookie. If more than one cookie of the same name exists for the given URL, the one with the longest path will be returned. For cookies with the same path length, the cookie with the earliest creation time will be returned.
https://developer.chrome.com/docs/extensions/reference/cookies/#method-get

What this is actually saying is even if we request a cookie for a subdomain (subdomain.domain.com) if there are collisions with a same name cookie in the domain (domain.com) it will pick the most recent.

I'm unsure if we should retrieve all the cookies and select the correct subdomain cookie, or if this is a non issue.

Should we dig deeper?

screenshots

create page

image

view page

image

@JPedroBorges JPedroBorges linked an issue Aug 25, 2023 that may be closed by this pull request
@bmg13
Copy link

bmg13 commented Aug 26, 2023

What this is actually saying is even if we request a cookie for a subdomain (subdomain.domain.com) if there are collisions with a same name cookie in the domain (domain.com) it will pick the most recent.

Would in any scenario the most recent not be the one you would want?

function tabToStringDomain(tab) {
const url = new URL(tab.url);
function tabToStringDomain(inputUrl) {
const url = new URL(inputUrl.startsWith("http") ? inputUrl : `http://${inputUrl}`);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a suggestion of setting a const "http://" and use it twice here, allowing some (although minor) reuse. Would assume no issue when https is used

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, we are just concatenating HTTP to form a valid URL in order to validate it with the URL class, so no hard in just doing HTTP.
It makes sense, I will add it as a constant.

Comment on lines 76 to 78
function isDomainMatch(itemDomain, cookieDomain) {
return itemDomain === cookieDomain || "." + itemDomain === cookieDomain;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possible misconception from my side, but is the next viable?

Suggested change
function isDomainMatch(itemDomain, cookieDomain) {
return itemDomain === cookieDomain || "." + itemDomain === cookieDomain;
}
function isDomainMatch(itemDomain, cookieDomain) {
return itemDomain === cookieDomain.substring(1);
}

Copy link
Member Author

@JPedroBorges JPedroBorges Sep 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my experience, we still need to validate the .domain.comand domain.com since I've seen both cases. Although it seems that the extra dot is not necessary.
But using the substring seems a neater approach. Thank you for the suggestion 👍🏻

@Marianarodrigues7 Marianarodrigues7 added the minor Just a minor change label Sep 1, 2023
Copy link
Contributor

@Marianarodrigues7 Marianarodrigues7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my understanding of your PR, once we set a custom value for a cookie item (without a defined domain), we assume the cookie domain is the same as the current tab.

If so, we should also do something in the apply function to our store. From what I can see, in the setter functions for our store we are just updating the value and not applying the domain.
Although you are doing a domain validation in getCookie, we don't see/have this information in our badges since it's not stored in our storeItems list.

I don't know if this was intentional (not having this information attached to the cookieItem when we assume the domain) but we can discuss it offline 🐶

}

if (domain) {
const domainLabel = newLabelWithBadge({ label: "Domain", value: domain || "" });
Copy link
Contributor

@Marianarodrigues7 Marianarodrigues7 Sep 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not for this MVP, but we have to consider, in terms of design, big values here. Having 2 or 3 badges with medium values might break the badge text since we are fixing our extension max width.
Not sure if an ellipsis would be the best UX but let's discuss this offline.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

if (domain) {
const domainLabel = newLabelWithBadge({ label: "Domain", value: domain || "" });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably my fault here from a previous PR (subkey) but we should remove this:

Suggested change
const domainLabel = newLabelWithBadge({ label: "Domain", value: domain || "" });
const domainLabel = newLabelWithBadge({ label: "Domain", value: domain});

We are already checking if the value exists to render the badge.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also update subkey above.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad on copy and past. Nice catch 👍

}

function itemFooter({ id, key, subKey }) {
function itemFooter({ id, domain, key, subKey }) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note: Following our design review about the badge & big values issue, we should review this component itemFooter. It's getting bigger and messy with new features.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your concern. Create a new issue where we can properly address it: #104

async function saveCookieValue(tab, key, subKey = "", domain, value) {
try {
return await chromeSaveCookieValue(tab, key, subKey, value);
return await chromeSaveCookieValue(tab, key, subKey, domain, value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This chromeSaveCookieValue function is getting crowded in terms of args, so probably it would be easier to use having it grouped some of these by their context - tab, {context of cookie}:

Suggested change
return await chromeSaveCookieValue(tab, key, subKey, domain, value);
return await chromeSaveCookieValue(tab, {key, subKey, domain, value});

WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, I'm strongly inclined to include typescript in the project.
Making this kind of changes is starting to get a bit scary 😅

I'm a bit resistant to make this change in this PR because by changing this, I feel like we would need to change local and session storage as well, which are out of scope for this PR.
What do you reckon if we move this change to a different issue?

@JPedroBorges
Copy link
Member Author

JPedroBorges commented Sep 3, 2023

@Marianarodrigues7

we assume the cookie domain is the same as the current tab.

Yes, on the initial implementation of the cookie flow, we were just looking at cookies from top level domain of the current tab.
I understand that this might be a bit limiting since we are excluding the “cross-domain cookies” as we often see in advertisement cookies.
Do you foresee the need of including those as well? I'm unsure how feasible it is to do.
image

we don't see/have this information in our badges

Assuming that we are not working with cookies outside of the top level domain, the cookie will be applied to the current domain. This means, whatever you are on localhost or, domain.com you are still able to use the same entry for both situations.
The whole point of the new domain field, was to control where the cookie was stored.
image
In this scenario, we have the same key being set on different domain levels. And the point of this change is for the user to be able to choose which one he wants to see.
Maybe we could “lock” the top level domain, and give the ability for the user to choose only the subdomain? “Maintaining the consistency between tabs”?

@bmg13

Would in any scenario the most recent not be the one you would want?

This is something that I'm really struggling with. I'm not going to bite the bullet, I'm changing the implementation to list all cookies and pick the one that is correct instead of relying on chrome cookies API.


Furthermore, contrary to my beliefs that domains always started with . to be retro compatible with older browsers, I've found some examples where this is not true for the same key.
image
Not sure if this is an edge case or a specific framework. Either way, since the domain are different we have 2 entries in the cookies list.
I really think there's a need to dig deeper into cookies before moving forward with this PR.

@JPedroBorges
Copy link
Member Author

Due to a lack of direction on this topic, I'm removing the input field.
Focusing on #92 and on a later date, we can come back to this topic with a fresh eyes.

@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

minor Just a minor change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add domain to cookies

4 participants