• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2024 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5const button_selector = 'button[aria-label=Consent]'
6const banner_selector = 'div[class=fc-consent-root]'
7var banner_observer;
8
9const button_observer = new MutationObserver(mutations => {
10  const button = document.querySelector(button_selector)
11  if (!button) {
12    return
13  }
14  // This script can run multiple times.
15  if (localStorage.getItem('already_run') === 'already_run') {
16    return
17  }
18  localStorage.setItem('already_run', 'already_run')
19  performance.mark('cookie_banner_created')
20  const banner_node = document.querySelector(banner_selector)
21  banner_observer = new MutationObserver(function(e) {
22    e.forEach(function(m) {
23      m.removedNodes.forEach(function(n) {
24        if (n === banner_node) {
25          performance.mark('cookie_banner_gone')
26        }
27      })
28    })
29  });
30  banner_observer.observe(banner_node.parentNode, {childList: true});
31  button.click()
32})
33
34button_observer.observe(document, {childList: true, subtree: true});
35