Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interact with an extension on Firefox #86

Open
kilted-andres opened this issue Nov 4, 2022 · 9 comments
Open

Interact with an extension on Firefox #86

kilted-andres opened this issue Nov 4, 2022 · 9 comments
Labels
enhancement New feature or request

Comments

@kilted-andres
Copy link

kilted-andres commented Nov 4, 2022

No description provided.

@kilted-andres
Copy link
Author

Hi,

I manage to launch the Nightly-browser (Firefox) with my local extension file thanks to your package. Thanks, its great!

Now I am trying to read the UUID of the extension in order to laund the moz-extension://{extension-UUID}/popup.html site of it and test as usual.

I normally read the UUID from this page: about:debugging#/runtime/this-firefox; but playwright hangs waiting for it to load. It is a local page and playwright is waiting a server response that is not comming. The problem is, that I cannot interact with the page and read the content of its elements because of this.

Do you know a workaround to interect with about: pages?
Or better, is there another way to read my extension UUID?

Best wishes,
Andrés

@kilted-andres
Copy link
Author

kilted-andres commented Nov 7, 2022

So, I managed to get the UUID from another way. Here the code for it:

`
const page = await context.newPage();
const ffremote = await remote.connect(RDP_PORT);
const response= await ffremote.client.request('listAddons');
console.log(response);

const extension: any = response.addons.find((i: any) => i.name === 'myExtensionName');

if (!extension) throw new Error("no extension loaded");

const match: any = extension.manifestURL.match(/moz-extension:\/\/(.+)\/manifest.json/);

const extensionUUID = match[1];
if (!extensionUUID) throw new Error('extension internal UUID not found');
console.log('extension UUID', extensionUUID);`

Trying to interact with the moz-extension://{extension-UUID}/popup.html is still giving me trouble. Playwright still fails waiting for a "load" event.

@chrmod
Copy link

chrmod commented Jan 17, 2023

We run into same problems with Playwright timeout on extension page load.

navigating to "moz-extension://3916d385-f277-4b99-af03-868931d9887e/app/templates/onboarding.html", waiting until "load"

@adrienbrault
Copy link

You can force a static UUID to be used when testing an extension:

  1. Use the browser_specific_settings manifest.json option to define an extension id:
{
  "browser_specific_settings": {
    "gecko": {
      "id": "[email protected]"
    }
  }
}
  1. After using withExtension from this package, set extensions.webextensions.uuids using firefoxUserPrefs:
const context = await browserTypeWithExtension.launch({
  firefoxUserPrefs: {
    "extensions.webextensions.uuids": JSON.stringify({
      "[email protected]": "2975768f-5c9f-4941-86e9-c53dfb667d84"
    })
  }
})

@kilted-andres kilted-andres changed the title How to read the UUID from the extension? Interact with an extension on Firefox Jun 27, 2023
@olso-nordsec
Copy link

olso-nordsec commented Jul 26, 2023

@chrmod problem is that moz-extension:// seems to be privileged page

this lib works if you try to navigate to e.g. https://google.com

i'm looking in about:config for a flag to turn this off


update 1

DEBUG=pw:* npx playwright test tests/smoke.spec.ts --project='Firefox'

;5;207m+1s\u001b[0m\n"}}} +0ms
  pw:channel:event {
  pw:channel:event   guid: 'frame@f8a92142e63f0ccf973137c336ecfda2',
  pw:channel:event   method: 'loadstate',
  pw:channel:event   params: { add: 'networkidle' }
  pw:channel:event } +1s
  pw:test:protocol ◀ RECV {"method":"__dispatch__","params":{"method":"stdErr","params":{"text":"  \u001b[30;1mpw:browser \u001b[0m[pid=41441][err] JavaScript warning: resource://gre/modules/UpdateService.sys.mjs, line 3860: unreachable code after return statement \u001b[30m+28s\u001b[0m\n"}}} +0ms
  pw:browser [pid=41441][err] JavaScript warning: resource://gre/modules/UpdateService.sys.mjs, line 3860: unreachable code after return statement +28s
  pw:test:protocol ◀ RECV {"method":"__dispatch__","params":{"method":"stdErr","params":{"text":"  \u001b[30;1mpw:browser \u001b[0m[pid=41441][out] console.error: (new Error(\"Polling for changes failed: The URI is malformed..\", \"resource://services-settings/remote-settings.sys.mjs\", 324)) \u001b[30m+3ms\u001b[0m\n"}}} +0ms
  pw:browser [pid=41441][out] console.error: (new Error("Polling for changes failed: The URI is malformed..", "resource://services-settings/remote-settings.sys.mjs", 324))

it seems that playwright firefox patch might be causing some issues

https://github.com/microsoft/playwright/blob/1277ec99008898cba23c3511d024972e42409963/browser_patches/firefox/patches/bootstrap.diff#L2590

causing https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Stmt_after_return


update 2

but i guess the core issue is this line

https://github.com/microsoft/playwright/blob/1277ec99008898cba23c3511d024972e42409963/browser_patches/firefox/juggler/content/JugglerFrameChild.jsm#L41

@chrmod
Copy link

chrmod commented Nov 17, 2023

@olso-nordsec thanks for great analysis!

@dgozman can you please explain what's the reason behind https://github.com/microsoft/playwright/blob/1277ec99008898cba23c3511d024972e42409963/browser_patches/firefox/juggler/content/JugglerFrameChild.jsm#L41 ?

Should this issue be moved to under the main playwright repo?

@dgozman
Copy link

dgozman commented Nov 17, 2023

@chrmod Playwright does not support Firefox extensions, thus the line you linked to.

@chrmod
Copy link

chrmod commented Jan 3, 2024

@dgozman I do understand that the team does no support the Firefox extension. I'm asking, as perhaps with some changes like removal of guards mentioned we could get some functionality running. Would you be open for partial support if driven by community?

@jochen-testingbot
Copy link

Any updates on this? We are also looking into testing the UI of Firefox extensions. Can https://github.com/microsoft/playwright/blob/1277ec99008898cba23c3511d024972e42409963/browser_patches/firefox/juggler/content/JugglerFrameChild.jsm#L41 be removed, would this help to test the extension?

Right now Playwright waits on the page load and is unable to interact with the page.

@ueokande ueokande added the enhancement New feature or request label Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants