JavaScript Document browsingTopics() Method

Beginner
⏱️ 12 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Deprecated
Non-standard
Instance method

What You’ll Learn

document.browsingTopics() is a deprecated, non-standard instance method from the Topics API. It returns a Promise of topic objects for interest-based advertising. Learn the return shape, skipObservation, enrollment requirements, why MDN recommends HTTP headers instead, and five try-it labs for educational reference.

01

Kind

Instance method

02

Returns

Promise → topics[]

03

Status

Deprecated

04

Also

Non-standard

05

Option

skipObservation

06

Requires

Enrollment

Introduction

Third-party cookies are being phased out in many browsers. Google’s Privacy Sandbox proposed alternatives for ad targeting, including the Topics API—a way to share coarse interest categories (topics) instead of cross-site tracking cookies.

MDN: Document.browsingTopics() returns a promise that fulfills with an array of objects representing the top topics for the user, one from each of the last three epochs. By default, calling it also records the current page visit as observed so the page hostname can be used in future topic calculation.

⚠️
Deprecated & non-standard (MDN)

This tutorial explains the API for learning and legacy code review only. MDN does not recommend using it in production. Prefer Topics HTTP headers when available, and avoid building new features on this method.

Related tutorials: ariaNotify(), Document constructor, JavaScript hub.

Understanding document.browsingTopics()

An instance method on the page’s document object, part of the Topics API (Privacy Sandbox).

  • Returns — a Promise resolving to up to three topic objects (MDN).
  • Each topic objecttopic, configVersion, modelVersion, taxonomyVersion, version (MDN).
  • Default behavior — observes the current page for topics unless skipObservation: true (MDN).
  • Enrollment — calling site must complete Privacy Sandbox enrollment (MDN).
  • Permissions Policybrowsing-topics can block usage (MDN).
  • Performance — MDN advises HTTP header-based Topics features when headers can be modified.

📝 Syntax

General forms of Document.browsingTopics (MDN):

JavaScript
browsingTopics()
browsingTopics(options)

Parameters

  • options (optional) — an object that may include:
    • skipObservation — boolean. If true, the browser does not observe topics when invoked. Default false (MDN).

Return value

A Promise that fulfills with an array of up to three topic objects (MDN).

Example topic object (MDN / Chrome)

JavaScript
{
  "configVersion": "chrome.1",
  "modelVersion": "1",
  "taxonomyVersion": "1",
  "topic": 43,
  "version": "chrome.1:1:1"
}

Exceptions

  • Topics API disallowed by browsing-topics Permissions Policy (MDN).
  • Site not enrolled in Privacy Sandbox enrollment (MDN).

Common patterns

JavaScript
// Feature-detect first
if (typeof document.browsingTopics !== "function") {
  console.log("browsingTopics not available");
} else {
  const topics = await document.browsingTopics();
  console.log(topics);
}

// Read without observing this page
const topicsOnly = await document.browsingTopics({ skipObservation: true });

⚡ Quick Reference

GoalCode / note
Get topicsawait document.browsingTopics()
Skip observationawait document.browsingTopics({ skipObservation: true })
Feature-detecttypeof document.browsingTopics === "function"
Topic ID fieldtopicObject.topic
Send to ad serverfetch(url, { body: JSON.stringify(topics) })
MDN statusDeprecated & Non-standard

🔍 At a Glance

Four facts about document.browsingTopics().

Returns
Promise

Topic array

Status
deprecated

MDN

Standard
no

Unofficial draft

Enroll?
required

Privacy Sandbox

📋 Topic object fields

PropertyMeaning
topicNumeric topic ID in the taxonomy (MDN)
configVersionAlgorithm config version (excluding model) (MDN)
modelVersionClassification model version (MDN)
taxonomyVersionTaxonomy version used (MDN)
versionColon-joined config:model:taxonomy (MDN)

Examples Gallery

Examples follow MDN Document: browsingTopics() for educational reference. The API may be unavailable without enrollment or in most browsers.

📚 Getting Started

Feature-detect and read topics safely.

Example 1 — Basic await document.browsingTopics()

Get the topic array when the method exists and enrollment allows it.

JavaScript
try {
  const topics = await document.browsingTopics();
  console.log(topics.length, "epoch topic(s)");
  console.log(topics);
} catch (err) {
  console.error("browsingTopics failed:", err.message);
}
Try It Yourself

How It Works

MDN: up to three objects, one per recent epoch. Empty or error is normal outside enrolled Chrome contexts.

Example 2 — Feature Detection

Check whether the method exists before calling it.

JavaScript
if (typeof document.browsingTopics === "function") {
  console.log("browsingTopics API present (may still require enrollment)");
} else {
  console.log("browsingTopics not supported in this browser");
}
Try It Yourself

How It Works

Presence of the function does not guarantee a successful call—enrollment and policy still apply.

📈 Practical Patterns

skipObservation, field inspection, and MDN’s ad request flow.

Example 3 — skipObservation: true

Read topics without recording this page visit as observed (MDN).

JavaScript
const topics = await document.browsingTopics({
  skipObservation: true
});

console.log("Topics without observing this page:", topics);
Try It Yourself

How It Works

Default false means the hostname may enter future topic calculation. Use true when you only want to read, not observe.

Example 4 — Inspect topic object fields

Log each property MDN documents on topic objects.

JavaScript
const topics = await document.browsingTopics();

topics.forEach((t, i) => {
  console.log(`Epoch ${i + 1}:`, {
    topic: t.topic,
    version: t.version,
    taxonomyVersion: t.taxonomyVersion
  });
});
Try It Yourself

How It Works

The numeric topic ID maps to a taxonomy of interests maintained by the browser vendor.

Example 5 — MDN: fetch ad creative with topics

Pass topics to an ad endpoint in a POST body (MDN example pattern).

JavaScript
const topics = await document.browsingTopics();

const response = await fetch("https://ads.example/get-creative", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify(topics),
});

const creative = await response.json();
// Display ad using creative
Try It Yourself

How It Works

MDN’s official flow: read topics, send to ad tech, receive creative JSON. This tutorial simulates the fetch for learning.

🚀 Historical Use Cases

  • Interest-based ads — share coarse topics instead of third-party cookies (Privacy Sandbox).
  • Ad server requests — include topics JSON in a subsequent fetch (MDN example).
  • Read-only analyticsskipObservation: true when you must not observe the page.
  • Legacy code review — understand Topics API calls in older ad integrations.
  • Not for new apps — MDN deprecated; vendor opposition and limited support.
  • Prefer headers — MDN recommends HTTP Topics headers when modifiable.

🧠 How browsingTopics() Works

1

Call on document

await document.browsingTopics(options) (MDN).

Invoke
2

Policy & enrollment check

Throws if blocked by Permissions Policy or not enrolled (MDN).

Gate
3

Observe page (default)

Unless skipObservation: true, hostname may enter topic calculation (MDN).

Observe
4

Promise resolves

Up to three topic objects returned for ad targeting or logging.

📝 Notes

  • MDN: Deprecated and Non-standard.
  • Two browser vendors oppose the feature (MDN standards positions).
  • Privacy Sandbox enrollment required for production use (MDN).
  • browsing-topics Permissions Policy can block the API (MDN).
  • Prefer Topics HTTP headers over this method when headers can be modified (MDN).
  • Related: ariaNotify(), Document(), JavaScript hub.

Browser Support

Document.browsingTopics() is Deprecated and Non-standard on MDN. Logos use the shared browser-image-sprite.png sprite. Historically tied to Chrome Privacy Sandbox; most browsers do not implement it. Do not rely on it in new code.

Deprecated · Non-standard

Document.browsingTopics()

Topics API — deprecated Privacy Sandbox method. Educational reference only.

Limited Chrome-era only
Google Chrome Historical / enrollment
Partial
Microsoft Edge Not supported
No
Mozilla Firefox Opposed / not supported
No
Apple Safari Not supported
No
Opera Not supported
No
Internet Explorer Not supported
No
browsingTopics() Deprecated

Bottom line: Do not use browsingTopics() in new projects. Prefer standard privacy-preserving patterns and avoid deprecated ad-tech APIs.

Conclusion

document.browsingTopics() was part of the Topics API for interest-based advertising. MDN marks it deprecated and non-standard. It returns a Promise of topic objects and may observe the current page by default.

Use this page for learning and legacy code only. Continue with caretPositionFromPoint(), ownerDocument, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Feature-detect before calling (legacy maintenance)
  • Wrap calls in try/catch for policy/enrollment errors
  • Use skipObservation: true when you must not observe the page
  • Prefer Topics HTTP headers when MDN says they are available
  • Plan migration away from deprecated Privacy Sandbox JS APIs

❌ Don’t

  • Build new products on browsingTopics() (MDN deprecated)
  • Assume enrollment or Chrome support equals wide browser support
  • Ignore Permissions Policy browsing-topics blocks
  • Confuse topics with personal identifiers or precise tracking
  • Skip user privacy review for ad-tech integrations

Key Takeaways

Knowledge Unlocked

Five things to remember about browsingTopics()

Deprecated Topics API — educational reference, not a build target.

5
Core concepts
⚠️02

Status

deprecated

MDN
🚫03

Standard

no

Draft
👁04

Observe

default on

skip opt
🛡05

Enroll

required

Sandbox

❓ Frequently Asked Questions

It returns a Promise that fulfills with an array of up to three topic objects — one from each of the last three epochs — representing the user's top topics for interest-based advertising (MDN).
MDN marks Document.browsingTopics() as Deprecated and Non-standard. It is not recommended for new production code. Two browser vendors oppose the feature.
A Promise resolving to an array of topic objects. Each object includes topic (ID number), configVersion, modelVersion, taxonomyVersion, and version (MDN).
An optional boolean in the options object. When true, the browser does not record the current page visit as observed for topics calculation. Default is false (MDN).
MDN: if the Topics API is blocked by a browsing-topics Permissions Policy, or if the site is not enrolled in the Privacy Sandbox enrollment process.
MDN advises preferring Topics API HTTP header features when you can modify headers, and falling back to browsingTopics() only when headers cannot be changed.
Did you know?

MDN notes that browsingTopics() does not use HTTP headers to send topics or mark observation—unlike other Topics API features—but HTTP header-based approaches are more performant and should be preferred when you can modify headers.

Next: caretPositionFromPoint()

Learn how to map viewport coordinates to a CaretPosition with offsetNode and offset.

caretPositionFromPoint() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful