Skip to content

fix: Use cached version of 'chrome' in app-init.js#24103

Merged
danjm merged 1 commit into
developfrom
fix-app-init
Apr 18, 2024
Merged

fix: Use cached version of 'chrome' in app-init.js#24103
danjm merged 1 commit into
developfrom
fix-app-init

Conversation

@danjm

@danjm danjm commented Apr 18, 2024

Copy link
Copy Markdown
Contributor

Description

When loading a prod mv3 build, we observed that a majority of the time, the offscreen document would not be created. In those case, we saw the following error in the service worker console:

runtime-lavamoat.js:13190
Uncaught Error: LavaMoat - property "chrome" of globalThis is inaccessible under scuttling mode. To learn more visit https://github.com/LavaMoat/LavaMoat/pull/360.
  at Object.get (runtime-lavamoat.js:13190:11)
  at app-init.js:1:1766
get	@	runtime-lavamoat.js:13190
(anonymous)	@	app-init.js:1

Which comes from this code in app-init.js:

async function createOffscreen() {
  if (await chrome.offscreen.hasDocument()) {
    return;
  }

  await chrome.offscreen.createDocument({
    url: './offscreen.html',
    reasons: ['IFRAME_SCRIPTING'],
    justification:
      'Used for Hardware Wallet and Snaps scripts to communicate with the extension.',
  });

  console.debug('Offscreen iframe loaded');
}

The solution is to cache a version of chrome before it has been scuttled.

Open in GitHub Codespaces

Related issues

Fixes:

Manual testing steps

  1. yarn dist:mv3
  2. Install at chrome://extensions
  3. A second or so after the service worker is created, the offscreen document should be created.
  4. Reload the extension 10 times, the offscreen document should be created every time

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've completed the PR template to the best of my ability
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

@danjm danjm requested a review from a team as a code owner April 18, 2024 09:02
@github-actions

Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label Apr 18, 2024
@danjm danjm changed the title Use cached version of 'chrome' in app-init.js fix: Use cached version of 'chrome' in app-init.js Apr 18, 2024
@danjm danjm added the team-extension-platform Extension Platform team label Apr 18, 2024
@codecov

codecov Bot commented Apr 18, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.60%. Comparing base (af2647e) to head (af2c476).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop   #24103   +/-   ##
========================================
  Coverage    67.60%   67.60%           
========================================
  Files         1251     1251           
  Lines        49000    49000           
  Branches     12793    12793           
========================================
  Hits         33125    33125           
  Misses       15875    15875           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@metamaskbot

Copy link
Copy Markdown
Collaborator
Builds ready [af2c476]
Page Load Metrics (2172 ± 748 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint7388821917182
domContentLoaded10147443416
load59446321721559748
domInteractive10147443416
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@danjm danjm merged commit d130cde into develop Apr 18, 2024
@danjm danjm deleted the fix-app-init branch April 18, 2024 14:35
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 18, 2024
@metamaskbot metamaskbot added the release-11.16.0 Issue or pull request that will be included in release 11.16.0 label Apr 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

INVALID-PR-TEMPLATE PR's body doesn't match template release-11.16.0 Issue or pull request that will be included in release 11.16.0 team-extension-platform Extension Platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants