privacy-sandbox-dev-support icon indicating copy to clipboard operation
privacy-sandbox-dev-support copied to clipboard

browsingTopics() get resolved to a value like this ["8bac7943-8016-4cfc-9e99-bc30fccb3148"]

Open nataliGitHub opened this issue 1 year ago • 27 comments
trafficstars

Hello, I use document.browsingTopics() method and in some cases it works correctly resolving to an array with valid json like [{"configVersion":"chrome.1","modelVersion":"4","taxonomyVersion":"2","topic":229,"version":"chrome.1:2:4"}] but sometimes we get a value like this one ["8bac7943-8016-4cfc-9e99-bc30fccb3148"].

What does it mean? Is it in my power to change something on my side to get a right result?

Thank you.

nataliGitHub avatar Feb 15 '24 21:02 nataliGitHub

Hi @nataliGitHub

Thanks for reporting this — I'll investigate.

Could you let me know the version of Chrome and, if possible, add a screenshot of chrome://topics-internals?

samdutton avatar Feb 16 '24 09:02 samdutton

Thank you for looking at it, Sam. A screenshot is not possible. The user_agent is Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

nataliGitHub avatar Feb 16 '24 15:02 nataliGitHub

Hello Sam,

I was trying to reach you on twitter but unsuccessfully. I can not send you any messages there. That is why I am writing to you right here.

I have a question about Topics API. I am trying to understand why we are getting so many responses like [].

Do I understand it right that in order for document.browsingTopics() to return an array of valid topics, the page has to have links or ads, something to click on to redirect to another page, that bring you to the other page that has an iframe with the browsingTopics() method call?

For owned media pages I do not anticipate links or ads that refer you to the different pages.

If my understanding is approximately right, it would mean that for owned media we will always get [] in a response unless the initial page itself can get into the response as a topic and then we will get an array with 1 element. Please correct me if I am wrong here.

Also, is it right that when I navigate to page Y after I visit page X (not using a link from X to Y), then I get a topic that is associated with page Y in browsingTopics() response of page X?

Thank you so much, Sam! This staff is tricky. I appreciate your first hand help!

Natalia.

On Fri, Feb 16, 2024 at 4:47 AM Sam Dutton @.***> wrote:

Hi @nataliGitHub https://github.com/nataliGitHub

Thanks for reporting this — I'll investigate.

— Reply to this email directly, view it on GitHub https://github.com/GoogleChromeLabs/privacy-sandbox-dev-support/issues/258#issuecomment-1948060822, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADY5SMJP6LIUF347SLZCT33YT4TLNAVCNFSM6AAAAABDK7DN26VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNBYGA3DAOBSGI . You are receiving this because you were mentioned.Message ID: @.*** .com>

nataliGitHub avatar Feb 16 '24 15:02 nataliGitHub

Hi @nataliGitHub

Could you provide some sample code where you're accessing document.browsingTopics()?

Also — would you be able to provide a screenshot of just the Features and Parameters tab from chrome://topics-internals? No worries if not.

Sam

samdutton avatar Feb 16 '24 16:02 samdutton

This is a sample code of setting the response in object a and passing it further : document.browsingTopics() .then(function(topics) { a.topics = JSON.stringify(topics); }) .catch(function(error) { console.log("topics error = ", error); });

I just realized that in that code I did not check for if ('browsingTopics' in document && document.featurePolicy.allowsFeature('browsing-topics')) {...} Maybe it would help to avoid the wrong response. Do you think it might? I am going to add this condition and test. Screenshot is not possible unfortunately. I cannot reproduce it locally where I would be able to send a screenshot.

Thank you.

nataliGitHub avatar Feb 16 '24 17:02 nataliGitHub

in order for document.browsingTopics() to return an array of valid topics, the page has to have links or ads, something to click on to redirect to another page, that bring you to the other page that has an iframe with the browsingTopics() method call?

Also, is it right that when I navigate to page Y after I visit page X (not using a link from X to Y), then I get a topic that is associated with page Y in browsingTopics() response of page X?

Topics callers only receive topics that they have observed for the user. Callers have two ways to signify to the browser that a topic has been observed for a user.

JavaScript API

Call document.browsingTopics() from an iframe embedded in pages the user visits.

document.browsingTopics() returns topics for the user, but it also signifies to the browser that a topic has been observed by a caller for a user. If allowed by user settings and site permissions, calling this method causes the browser to record the host of URL of the top-level page, and record that the caller observed the page visit. That record will be used at the end of each week ("epoch") to calculate the user's top topics.

HTTP headers

Topics can be accessed and observed with HTTP headers in two ways:

  • fetch(): Add {browsingTopics: true} to the options parameter of a fetch() request. The Topics fetch demo shows a simplified example of this.
  • iframe attribute: Add the browsingtopics attribute to an <iframe> element, or set the equivalent JavaScript property iframe.browsingTopics = true. The registrable domain of the iframe source is the caller domain: for example, for <iframe src="https://example.com" browsingtopics></iframe>: the caller is example.com.

samdutton avatar Feb 16 '24 17:02 samdutton

document.browsingTopics() returns a promise that resolves to an array of topics. I think here you're attempting to add a stringified promise as a property of the object a.

You might want to use something like this:

async function getTopics() {
  const topics = await document.browsingTopics();
  console.log(topics);
} 

try {
  getTopics();
} catch (error) {
  console.error(error);
}

samdutton avatar Feb 16 '24 17:02 samdutton

My version of code works in most cases, only sometimes it produces the output I was asking about. Unfortunately the js ES5 version that we use is not allowing me to use await/async pattern. This is a screenshot from my browser where my version of code works properly: image

nataliGitHub avatar Feb 16 '24 17:02 nataliGitHub

My version of code works in most cases

Apologies — I confused myself :). Realise now your code doesn't do what I suggested (i.e., as you say, it should work!)

Taking another look.

samdutton avatar Feb 16 '24 18:02 samdutton

Hi @nataliGitHub, is that the same code that is sometimes giving you results like "8bac7943-8016-4cfc-9e99-bc30fccb3148"? And are those bad values appearing in the console log, or when you look at the property a.topics later on?

The string "8bac7943-8016-4cfc-9e99-bc30fccb3148" looks like a UUIDv4. Those are not used in the Topics API at all, which makes it extremely hard to think of a way that could happen. But we do use those UUIDs in the context of the Protected Audience API; that is the kind of string returned by navigator.createAuctionNonce(). Is there any chance you are testing PA also, somewhere else on the same page, and the two API's return values are somehow overwriting one another in your test code?

michaelkleber avatar Feb 16 '24 18:02 michaelkleber

No problem, Sam. Thank you for looking at it.

Hi Michael,

  1. the code that produced bad value among others does not have the first line with the condition. We called browsiingTopic() not checking if it is allowed.
  2. We do not see the bad value in a console log. We do see it in our logs at a later point. Object a is passed to some tag function as a parameter, then tag is fired, then after some data collation we see it in our logs.
  3. I checked the site, we do not have any usage of navigator.createAuctionNonce(). Thank you for working on our issue.

nataliGitHub avatar Feb 16 '24 19:02 nataliGitHub

Sam,

I will try to rephrase my above questions if I may.

  1. Since owned media sites do not usually have links(ads) to other sites, should we expect any topics to be observed from an owned media site except its own topic(s)?

  2. If the user navigates from site X to site Y without using links on site X, would/should the site X observe the topic that corresponds to site Y?

Thank you.

nataliGitHub avatar Feb 16 '24 20:02 nataliGitHub

Hi @nataliGitHub

Since owned media sites do not usually have links(ads) to other sites, should we expect any topics to be observed from an owned media site except its own topic(s)?

If the user navigates from site X to site Y without using links on site X, would/should the site X observe the topic that corresponds to site Y?

Topics is designed for scenarios where a provider (e.g. an ad tech) has a presence on multiple sites.

A Topics caller will only receive topics that they have observed for a user, so the caller needs to have a presence on pages the user visits (like the demo sites on topics-fetch-demo.glitch.me).

For example, an ad tech might provide an iframe that accesses the Topics API, to observe topics for users. This iframe can be embedded on the ad tech's partner sites, to allow topics to be recorded (where allowed by user and site settings) on pages where the iframe is embedded. The ad tech can then use the topics they observed for a user to help select ads (e.g. on a publisher site).

Hope that makes sense — please let me know if it doesn't answer your question!

Sam

samdutton avatar Feb 19 '24 12:02 samdutton

Thank you very much, Sam, for clarifications. It helps a lot.

Natalia.

nataliGitHub avatar Feb 22 '24 23:02 nataliGitHub

Hi @nataliGitHub -- slightly lost track of this. Do you still have unanswered questions? If so, let us know. Thanks!

samdutton avatar Mar 06 '24 15:03 samdutton

There hasn't been any activity on this bug for several weeks, so I'll close it. Feel free to reopen if necessary.

samdutton avatar Mar 20 '24 15:03 samdutton

Hi, how do you solve it @nataliGitHub ? We are having the same issue here:

getBrowsingTopics(): Observable<unknown> {
        try {
            return from((document as any).browsingTopics())
        } catch (error) {
            console.log(error)
            return of([]);
        }
    }

And we receive the followings values:

image

We are sending the response of getBrowsingTopics() inside a JSON to our analytics service.

patricio-navarro avatar Mar 25 '24 09:03 patricio-navarro

Hi @patricio-navarro — thanks for providing the code and values. Looking into this now.

@nataliGitHub FYI

samdutton avatar Mar 25 '24 12:03 samdutton

@patricio-navarro Would you be able to provide a demo to repro this?

samdutton avatar Mar 25 '24 14:03 samdutton

Hi @samdutton please check this sample ad preview:

https://preprod-studio.connected-stories.com/live-preview-suite/12318/19809/10622/2 or this sample ad tag: https://preprod-studio.connected-stories.com/vastManager/vpaid/2?cs_cid=19809&cs_csid=10619&cs_sid=12315&dsp=None&cs_geoInfo=0&cs_weather=0&cs_env=EMEA&cb=[CACHEBUSTING]&cs_gdpr=${GDPR}&cs_gdpr_consent=${GDPR_CONSENT_699}

Please let me know if this helps.

patricio-navarro avatar Mar 25 '24 15:03 patricio-navarro

Thanks @patricio-navarro.

Is it possible for you to check document.browsingTopics() at the point it's being called, to see if it's somehow being overridden?

I think document.browsingTopics.toString() should work, or you could use typeof document.browsingTopics.prototype.

@nataliGitHub You might also want to take a look at this.

samdutton avatar Mar 25 '24 18:03 samdutton

Might also be worth checking for extensions that might be overriding document.browsingTopics(), or otherwise interfering with the return value.

samdutton avatar Mar 27 '24 15:03 samdutton

Hi @patricio-navarro @nataliGitHub — were you able to check if document.browsingTopics() is somehow being overriden?

samdutton avatar Apr 03 '24 10:04 samdutton

Hi @samdutton I was not able to test it yet but I tried using the Console: image

image

This should work right?

When you said "Is it possible for you to check document.browsingTopics() at the point it's being called, to see if it's somehow being overridden?" how should I do it? maybe introducing some Console.log() ?

Thanks

patricio-navarro avatar Apr 03 '24 12:04 patricio-navarro

Hi @patricio-navarro

That looks fine from the console — though of course this will return topics observed for the user by the current origin, in this case https://preprod-studio.connected-stories.com.

When you said "Is it possible for you to check document.browsingTopics() at the point it's being called, to see if it's somehow being overridden?" how should I do it? maybe introducing some Console.log() ?

If you can insert code, call console.log(document.browsingTopics.toString()) or console.log(typeof document.browsingTopics.prototype) one line before document.browsingTopics() is called.

samdutton avatar Apr 03 '24 12:04 samdutton

Hi @samdutton I did a deeper check, and I found out that in fact this is working fine (I had a problem in my data processing pipeline). The problem is there, but is only in a small percentage of cases, could be due to another browser?

Thanks for the help.

patricio-navarro avatar Apr 09 '24 10:04 patricio-navarro

@patricio-navarro — great to hear you tracked down the problem! Thanks for letting us know.

@nataliGitHub — any progress?

samdutton avatar Apr 09 '24 10:04 samdutton

No further follow-up in >6 weeks, so I'll close this for now, but feel free to reopen.

samdutton avatar May 29 '24 12:05 samdutton