Page MenuHomePhabricator

[chrome-ext] Implement terms-of-service popup reminder behaviour
Open, HighPublic3 Estimated Story Points

Description

Background

In T377757 we created a spec for how the terms-of-service pop for the chrome extension should look and work.
The goal of this task is to implement the behaviours associated with reminding users to accept the terms-of-service if they ignore the popup during extension installation or update.

User story

As an experiment participant, I need to explicitly opt-in to the experiment before participating in it.

Requirements

The following behaviour should only occur when someone has installed the browser extension, then, they have not accepted or rejected the terms of service.

Popup reminder behaviour:

  • Show the popup when someone visits *.wikipedia.org (the popup should not appear automatically on any other domains)
  • Only show the popup once per browser session (a session ends when the browser is closed, and starts when it's opened again).
  • Stop showing the popup if the terms have been accepted.
  • Stop showing the popup if the terms have been rejected.

Screenshot_2024-10-18_at_12.29.14 PM.png (734×2 px, 163 KB)

BDD

Feature: Terms-of-Service Popup Reminder for Browser Extension

  Scenario: Show terms-of-service popup when conditions are met
    Given the browser extension is installed
    And the user has not accepted or declined the terms of service
    And the user visits any `*.wikipedia.org` domain
    When the browser session starts
    Then the terms-of-service popup appears once per session
    And no experiment runs until the terms of service are agreed to or declined

  Scenario: Stop showing terms-of-service popup after acceptance
    Given the terms-of-service popup is displayed
    And the user agrees to the terms
    When the page reloads
    Then the experiments start
    And the popup no longer appears in subsequent visits

  Scenario: Stop showing terms-of-service popup after rejection
    Given the terms-of-service popup is displayed
    And the user declines the terms
    When the user revisits the site
    Then the popup no longer appears
    And no experiments are run

Test Steps

Test Case 1: Verify Terms-of-Service Popup Behavior

  1. Install the browser extension.
  2. Visit any *.wikipedia.org domain without accepting or rejecting the terms of service.
  3. AC1: Confirm that the terms-of-service popup appears on the page.
  4. Close the browser and reopen it. Revisit any *.wikipedia.org domain.
  5. AC2: Confirm the popup appears only once during the new session.
  6. Accept the terms of service when the popup appears.
  7. Reload the page.
  8. AC3: Confirm that the experiments are enabled, and the popup no longer appears.
  9. Decline the terms of service on the popup (in a new browser session).
  10. AC4: Confirm that the popup no longer appears and no experiments are run.

Acceptance criteria

  1. The terms-of-service popup appears if someone installs the popup, does not accept or decline the terms of service, and then visits en.wikipedia.org
  2. The terms-of-service popup appears in those conditions only once per browser session.
  3. The terms-of-service popup stops appearing once the terms are accepted or declined.
  4. No experiment is running before the terms-of-service are agreed to or rejected.
  5. An experiment appears after the terms-of-service have been agreed to (after a page reload)

QA Results - Prod

This task was created by Version 1.2.0 of the Web team task template using phabulous

Event Timeline

I'm posting some generated code below that might accomplish this behaviour.
It keeps track of the last visited domain, current domain, stores the impression in the browser extension session storage, so when someone visits Wikipedia for the first time during a browser session, they'll be shown the popup once during that browser session.

const TOS_STORAGE_KEY = 'tos';
const POPUP_SHOWN_KEY = 'popup_shown_this_session';
let previousHostname = '';

chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
    // URL related variables
    const isComplete = changeInfo.status === 'complete';
    const url = new URL(tab.url);
    const currentHostname = url.hostname;
    const isWikipedia = currentHostname.endsWith('wikipedia.org');
    const wasWikipedia = previousHostname.endsWith('wikipedia.org');
    
    // Storage related variables
    const sessionResult = await chrome.storage.session.get(POPUP_SHOWN_KEY);
    const tosResult = await chrome.storage.local.get(TOS_STORAGE_KEY);
    
    // Early return
    if (!isComplete || !isWikipedia || wasWikipedia || 
        sessionResult[POPUP_SHOWN_KEY] || 
        tosResult[TOS_STORAGE_KEY] !== null) {
        previousHostname = currentHostname;
        return;
    }

    await chrome.action.openPopup();
    await chrome.storage.session.set({ [POPUP_SHOWN_KEY]: true });
    previousHostname = currentHostname;
});
Jdrewniak set the point value for this task to 3.Thu, Nov 7, 6:12 PM
Jdrewniak moved this task from Incoming to FY2024-25 Q2 Sprint 4 on the Web-Team-Backlog board.
Jdrewniak updated the task description. (Show Details)

I'm attaching a build of the extension for QA purposes.
This build might show two experiments running after the terms of service is accepted (but that can be ignored for this task).

Edtadros subscribed.

Test Result - Prod

Status: ✅ PASS
Environment: enwiki (chrome extension version 1.0.7)
OS: macOS
Browser: Chrome
Device: MS
Emulated Device: NA

Test Artifact(s):

Test Steps

Test Case 1: Verify Terms-of-Service Popup Behavior

  1. Install the browser extension.
  2. Visit any *.wikipedia.org domain without accepting or rejecting the terms of service.
  3. ✅ AC1: Confirm that the terms-of-service popup appears on the page. This is validated in T378098#10342378 AC2.
  4. Close the browser and reopen it. Revisit any *.wikipedia.org domain.
  5. ✅ AC2: Confirm the popup appears only once during the new session.

screenshot 21.mov.gif (1×1 px, 2 MB)

  1. Accept the terms of service when the popup appears.
  2. Reload the page.
  3. ✅ AC3: Confirm that the experiments are enabled, and the popup no longer appears.

screenshot 27.mov.gif (1×1 px, 3 MB)

The experiments are validated in T378098#10342378 AC4.

  1. Decline the terms of service on the popup (in a new browser session).
  2. ✅ AC4: Confirm that the popup no longer appears and no experiments are run.

screenshot 26.mov2.gif (966×1 px, 480 KB)