-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trigger refresh of Click to Load placeholders on request block (#1738)
Historically, the Click to Load placeholders were only drawn once at the point page load completed. That had two problems: 1. Sometimes placeholders would take too long to display, if the page took a long time to load fully. 2. Sometimes placeholders would not be displayed at all, if the blocked content was only created after page load had finished. To fix that, let's send a message to the content-scope-script to ensure that placeholders are refreshed each time a Click to Load request is blocked. Also tweak the response messages to be inline with the recent content-scope-script changes to make response messages easier to identify. Unfortunately the YouTube Click to Load integration tests need to be disabled for now, since we had to disable the "hideTrackingElement" option for now which breaks some of the YouTube SDK integration.
- Loading branch information
Showing
7 changed files
with
103 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import tdsStorage from './storage/tds' | ||
import { sendTabMessage } from './utils' | ||
|
||
/** | ||
* Find the enabled Click to Load rule actions for the given tab. | ||
* Note: Take care to ensure wait for the extension configuration to be ready | ||
* first. | ||
* @param {import('./classes/tab')} tab | ||
* @return {string[]} | ||
*/ | ||
export function getDefaultEnabledClickToLoadRuleActionsForTab (tab) { | ||
// Click to Load feature isn't supported or is disabled for the tab. | ||
if (!tab?.site?.isFeatureEnabled('clickToPlay')) { | ||
return [] | ||
} | ||
|
||
const clickToLoadSettings = | ||
tdsStorage?.config?.features?.clickToPlay?.settings | ||
|
||
// Click to Load configuration isn't ready yet. | ||
if (!clickToLoadSettings) { | ||
console.warn('Click to Load configuration not ready yet, skipped.') | ||
return [] | ||
} | ||
|
||
const enabledRuleActions = [] | ||
const { parentEntity } = tab.site | ||
|
||
for (let [entity, { ruleActions, state }] of Object.entries(clickToLoadSettings)) { | ||
// No rule actions, or entity is disabled. | ||
if (!ruleActions || ruleActions.length === 0 || state !== 'enabled') { | ||
continue | ||
} | ||
|
||
// TODO: Remove this workaround once the content-scope-scripts and | ||
// privacy-configuration repositories have been updated. | ||
if (entity === 'Facebook') entity = 'Facebook, Inc.' | ||
|
||
// Enabled Click to Load entity is third-party for this tab, note its | ||
// rule actions. | ||
if (parentEntity !== entity) { | ||
enabledRuleActions.push(...ruleActions) | ||
} | ||
} | ||
|
||
return enabledRuleActions | ||
} | ||
|
||
/** | ||
* Triggers a refresh of the Click to Load placeholders for the given tab. | ||
* @param {import('./classes/tab')} tab | ||
* @param {string} [ruleAction] | ||
* If provided, only placeholders associated with the entity containing that | ||
* rule action will be refreshed. By default, all placeholders will be | ||
* refreshed. | ||
*/ | ||
export async function displayClickToLoadPlaceholders (tab, ruleAction) { | ||
const message = { | ||
type: 'update', | ||
feature: 'clickToLoad', | ||
messageType: 'displayClickToLoadPlaceholders', | ||
options: { } | ||
} | ||
if (typeof ruleAction === 'string') { | ||
message.options.ruleAction = ruleAction | ||
} | ||
|
||
await sendTabMessage(tab.id, message) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters