From 51ffe8fa1e69d0d88abdd8b4c634139003d5bb8f Mon Sep 17 00:00:00 2001 From: Max Edell Date: Mon, 23 Sep 2024 09:05:01 -0700 Subject: [PATCH 1/2] fix: lazy suggestions, none on incognito --- tools/rum/elements/url-selector.js | 52 +++++++++++++++++------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/tools/rum/elements/url-selector.js b/tools/rum/elements/url-selector.js index 9442b567..8aa81f48 100644 --- a/tools/rum/elements/url-selector.js +++ b/tools/rum/elements/url-selector.js @@ -2,6 +2,10 @@ function getPersistentToken() { return localStorage.getItem('rum-bundler-token'); } +function isIncognitoMode() { + return new URL(window.location.href).searchParams.get('domainkey') === 'incognito'; +} + export default class URLSelector extends HTMLElement { constructor() { super(); @@ -41,32 +45,36 @@ export default class URLSelector extends HTMLElement { const img = this.querySelector('img'); img.src = `https://www.google.com/s2/favicons?domain=${input.value.split(':')[0]}&sz=64`; - const token = getPersistentToken(); - if (!token) { + if (!getPersistentToken()) { input.disabled = true; datalist.remove(); - } else { - fetch('https://rum.fastly-aem.page/domains?suggested=true', { - headers: { - accept: 'application/json', - authorization: `Bearer ${token}`, - }, - }).then(async (resp) => { - if (!resp.ok) { - datalist.remove(); - } else { - const { domains } = await resp.json(); - domains.forEach((domain) => { - const option = document.createElement('option'); - option.value = domain; - datalist.appendChild(option); - }); - } - }).catch(() => { - datalist.remove(); - }); } + input.addEventListener('mouseover', () => { + const token = getPersistentToken(); + if (token && !isIncognitoMode()) { + fetch('https://rum.fastly-aem.page/domains?suggested=true', { + headers: { + accept: 'application/json', + authorization: `Bearer ${token}`, + }, + }).then(async (resp) => { + if (!resp.ok) { + datalist.remove(); + } else { + const { domains } = await resp.json(); + domains.forEach((domain) => { + const option = document.createElement('option'); + option.value = domain; + datalist.appendChild(option); + }); + } + }).catch(() => { + datalist.remove(); + }); + } + }, { once: true }); + input.addEventListener('focus', () => { input.select(); }); From 2d38bc40c29aa9a9a66b9f289e3171b71289555d Mon Sep 17 00:00:00 2001 From: Max Edell Date: Mon, 23 Sep 2024 09:06:14 -0700 Subject: [PATCH 2/2] fix: add to oversight --- tools/oversight/elements/url-selector.js | 52 ++++++++++++++---------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/tools/oversight/elements/url-selector.js b/tools/oversight/elements/url-selector.js index 78f57f38..35d9ee77 100644 --- a/tools/oversight/elements/url-selector.js +++ b/tools/oversight/elements/url-selector.js @@ -2,6 +2,10 @@ function getPersistentToken() { return localStorage.getItem('rum-bundler-token'); } +function isIncognitoMode() { + return new URL(window.location.href).searchParams.get('domainkey') === 'incognito'; +} + export default class URLSelector extends HTMLElement { constructor() { super(); @@ -41,8 +45,7 @@ export default class URLSelector extends HTMLElement { const img = this.querySelector('img'); img.src = `https://www.google.com/s2/favicons?domain=${input.value.split(':')[0]}&sz=64`; - const token = getPersistentToken(); - if (!token) { + if (!getPersistentToken()) { input.disabled = true; datalist.remove(); @@ -55,28 +58,33 @@ export default class URLSelector extends HTMLElement { window.location.href = targetlocation.href; } }); - } else { - fetch('https://rum.fastly-aem.page/domains?suggested=true', { - headers: { - accept: 'application/json', - authorization: `Bearer ${token}`, - }, - }).then(async (resp) => { - if (!resp.ok) { - datalist.remove(); - } else { - const { domains } = await resp.json(); - domains.forEach((domain) => { - const option = document.createElement('option'); - option.value = domain; - datalist.appendChild(option); - }); - } - }).catch(() => { - datalist.remove(); - }); } + input.addEventListener('mouseover', () => { + const token = getPersistentToken(); + if (token && !isIncognitoMode()) { + fetch('https://rum.fastly-aem.page/domains?suggested=true', { + headers: { + accept: 'application/json', + authorization: `Bearer ${token}`, + }, + }).then(async (resp) => { + if (!resp.ok) { + datalist.remove(); + } else { + const { domains } = await resp.json(); + domains.forEach((domain) => { + const option = document.createElement('option'); + option.value = domain; + datalist.appendChild(option); + }); + } + }).catch(() => { + datalist.remove(); + }); + } + }, { once: true }); + input.addEventListener('focus', () => { input.select(); });