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

[Feature] Support running extensions with Firefox #7297

Open
Pooort opened this issue Jun 24, 2021 · 69 comments
Open

[Feature] Support running extensions with Firefox #7297

Pooort opened this issue Jun 24, 2021 · 69 comments

Comments

@Pooort
Copy link

Pooort commented Jun 24, 2021

Context:

  • Playwright Version: 1.9.0
  • Operating System: Linux 5.4 Ubuntu 20.04.2 LTS (Focal Fossa)
  • Node.js version: 14.17.1
  • Browser: Firefox

Can't connect to the Firefox browser using this code: #2644 (comment)

The code freezes on the:

const browser = await firefox.connect({ wsEndpoint });

I see the browser with extension started, but Playwright can't connect to Firefox.

@aslushnikov
Copy link
Collaborator

Can't connect to the Firefox browser using this code: #2644 (comment)

@Pooort Well, this was a best-effort hack that didn't age well. So overall, that's not a bug: it was never officially supported.

We probably can support it properly, but that's an engineering effort. The more upvotes this issue gets, the higher we'll prioritize it!

@aslushnikov aslushnikov changed the title [BUG] Can't connect to the Firefox running with web-ext [Feature] Support running extensions with Firefox Jun 24, 2021
@Badgerr
Copy link

Badgerr commented Jun 25, 2021

@aslushnikov I appreciate your effort. It would be nice to have extensions support. Voting up.

@sdklein
Copy link

sdklein commented Jun 25, 2021

agreed. this would be fantastic.

@rai-gaurav
Copy link

This is definitely a much needed feature.
Recently I was exploring to use Playwright and which going creating POC, I can to know through different github issues that Playwright always launch in incognito mode and there is not such easy way to launch a normal browser(#2071). Incognito mode is not great with testing extensions.

It would be great if there is easy support for extension across all browsers since its one of the USP of Playwright.

@selang
Copy link

selang commented Sep 27, 2021

It would be nice to have extensions support. Voting up.

@A-gambit
Copy link

A-gambit commented Mar 8, 2022

Hi, It will be great to have firefox extension support. Voting up.

@aslushnikov are there any plans to make it works?

@NuLL3rr0r
Copy link

I would also like to see this feature integrated.

@AxxiD
Copy link

AxxiD commented Jul 10, 2022

Being able to test a website with multiple browsers and commonly used extensions all with the same code will be a real game changer.

@ueokande
Copy link

ueokande commented Aug 1, 2022

I found another workaround to install add-ons to Firefox. Firefox allows installing addons via RDP (Remote Debugging Protocol). The following shows how to install addons by the RDP client implemented in web-ext.

import { firefox } from 'playwright';
// 'remote' is not defined by "exports" in package.json
import { connect } from './node_modules/web-ext/lib/firefox/remote.js';

const RDP_PORT = 12345;

(async () => {
  const browser = await firefox.launch({
    headless: false,
    args: [ '-start-debugger-server', String(RDP_PORT) ],
    firefoxUserPrefs: {
      'devtools.debugger.remote-enabled': true,
      'devtools.debugger.prompt-connection': false,
    }
  });

  const client = await connect(RDP_PORT);
  const resp = await client.installTemporaryAddon("path/to/addon/directory");
  console.log("Installed addon with ID", resp.addon.id);

  const page = await browser.newPage();
  await page.goto('https://mozilla.org');

  // ...
})();

Although this example imports an internal module, I believe it's better to use another client, such as Foxdriver (or implement a client yourself).

@szmarczak
Copy link
Contributor

szmarczak commented Aug 11, 2022

@ueokande Here's a full native Node.js implementation of this - no need to use web-ext or any external client:

import { Buffer } from 'buffer';
import net from 'net';

export const loadFirefoxAddon = (port: number, host: string, addonPath: string) => {
    return new Promise<boolean>((resolve) => {
        const socket = net.connect({
            port,
            host,
        });

        let success = false;

        socket.once('error', () => {});
        socket.once('close', () => {
            resolve(success);
        });

        const send = (data: Record<string, string>) => {
            const raw = Buffer.from(JSON.stringify(data));

            socket.write(`${raw.length}`);
            socket.write(':');
            socket.write(raw);
        };

        send({
            to: 'root',
            type: 'getRoot',
        });

        const onMessage = (message: any) => {
            if (message.addonsActor) {
                send({
                    to: message.addonsActor,
                    type: 'installTemporaryAddon',
                    addonPath,
                });
            }

            if (message.addon) {
                success = true;
                socket.end();
            }

            if (message.error) {
                socket.end();
            }
        };

        const buffers: Buffer[] = [];
        let remainingBytes = 0;

        socket.on('data', (data) => {
            while (true) {
                if (remainingBytes === 0) {
                    const index = data.indexOf(':');

                    buffers.push(data);

                    if (index === -1) {
                        return;
                    }

                    const buffer = Buffer.concat(buffers);
                    const bufferIndex = buffer.indexOf(':');

                    buffers.length = 0;
                    remainingBytes = Number(buffer.subarray(0, bufferIndex).toString());

                    if (!Number.isFinite(remainingBytes)) {
                        throw new Error('Invalid state');
                    }

                    data = buffer.subarray(bufferIndex + 1);
                }

                if (data.length < remainingBytes) {
                    remainingBytes -= data.length;
                    buffers.push(data);
                    break;
                } else {
                    buffers.push(data.subarray(0, remainingBytes));

                    const buffer = Buffer.concat(buffers);
                    buffers.length = 0;

                    const json = JSON.parse(buffer.toString());
                    queueMicrotask(() => {
                        onMessage(json);
                    });

                    const remainder = data.subarray(remainingBytes);
                    remainingBytes = 0;

                    if (remainder.length === 0) {
                        break;
                    } else {
                        data = remainder;
                    }
                }
            }
        });
    });
};

@bibinmohana
Copy link

Hello All ,

I have tried the below code in java to launch extension , its working but its getting launged in nightly . Is this still a limitation or something wrong with the code . Can some one help me here pls ?

Playwright playwright = Playwright.create()
Path extpath=Paths get("profile\extension)

List Args= new ArrayList<>();

Args.add("--dusable-extension-except="+extpath);
Args.add("--load-extension="+ extpath)

BrowserType.LaunchPersistentContextOptions lp= new BrowserType.LaunchPersistentContextOptions();
lp.setChannel("firefox")
lp.setHeadless(false)
lp.args=Args
lp.setDevtools(false)
Path path= Paths.get(path to profile folder)
BrowserContext browser= playwright.firefox().launchPersistentContext(path, lp)
Page page= browser.pages().get(0)
page.navigate()
....

The above cose is working with extensionbut its loading in Nightly .. is it a limitation or something wrong with code ?

@optionsx
Copy link

add pls.

@4n1qz5skwv
Copy link

add pls (python)

@ueokande
Copy link

Hi! I have published npm package which enables you to load an extensions on playwright.
https://github.com/ueokande/playwright-webextext

@aryangupta701
Copy link

@ueokande I used your package to install the addon. The addon installed successfully but it is asking for permissions and I am not able to give permissions to it. is there any way to do this ?

Screenshot from 2023-05-13 12-29-07

@gilgulim
Copy link

gilgulim commented Jun 8, 2023

Much needed! (java)

@xinlai-ni
Copy link

+1

kzar added a commit to kzar/duckduckgo-privacy-extension that referenced this issue Apr 30, 2024
…tion

We are migrating Chrome extension users over onto the manifest
v3 (MV3) build, in time for the June deadline[1]. Once that's
finished, only Firefox users will remain on the MV2 build. Let's
rename the build, release, and test scripts and related documentation
to reflect that change.

Note: We unfortunately can't remove the chrome-mv2 build target
      entirely, since Playwright does not yet support testing Firefox
      extensions[2]. To test the MV2 code via the integration tests,
      using the chrome-mv2 build is the best we can do for now.

1 - https://developer.chrome.com/blog/resuming-the-transition-to-mv3/
2 - microsoft/playwright#7297
kzar added a commit to kzar/duckduckgo-privacy-extension that referenced this issue Apr 30, 2024
…tion

We are migrating Chrome extension users over onto the manifest
v3 (MV3) build, in time for the June deadline[1]. Once that's
finished, only Firefox users will remain on the MV2 build. Let's
rename the build, release, and test scripts and related documentation
to reflect that change.

Note: We unfortunately can't remove the chrome-mv2 build target
      entirely, since Playwright does not yet support testing Firefox
      extensions[2]. To test the MV2 code via the integration tests,
      using the chrome-mv2 build is the best we can do for now.

1 - https://developer.chrome.com/blog/resuming-the-transition-to-mv3/
2 - microsoft/playwright#7297
kzar added a commit to kzar/duckduckgo-privacy-extension that referenced this issue Apr 30, 2024
…tion

We are migrating Chrome extension users over onto the manifest
v3 (MV3) build, in time for the June deadline[1]. Once that's
finished, only Firefox users will remain on the MV2 build. Let's
rename the build, release, and test scripts and related documentation
to reflect that change.

Note: We unfortunately can't remove the chrome-mv2 build target
      entirely, since Playwright does not yet support testing Firefox
      extensions[2]. To test the MV2 code via the integration tests,
      using the chrome-mv2 build is the best we can do for now.

1 - https://developer.chrome.com/blog/resuming-the-transition-to-mv3/
2 - microsoft/playwright#7297
kzar added a commit to kzar/duckduckgo-privacy-extension that referenced this issue Apr 30, 2024
…tion

We are migrating Chrome extension users over onto the manifest
v3 (MV3) build, in time for the June deadline[1]. Once that's
finished, only Firefox users will remain on the MV2 build. Let's
rename the build, release, and test scripts and related documentation
to reflect that change.

Note: We unfortunately can't remove the chrome-mv2 build target
      entirely, since Playwright does not yet support testing Firefox
      extensions[2]. To test the MV2 code via the integration tests,
      using the chrome-mv2 build is the best we can do for now.

1 - https://developer.chrome.com/blog/resuming-the-transition-to-mv3/
2 - microsoft/playwright#7297
kzar added a commit to kzar/duckduckgo-privacy-extension that referenced this issue May 1, 2024
…tion

We are migrating Chrome extension users over onto the manifest
v3 (MV3) build, in time for the June deadline[1]. Once that's
finished, only Firefox users will remain on the MV2 build. Let's
rename the build, release, and test scripts and related documentation
to reflect that change.

Note: We unfortunately can't remove the chrome-mv2 build target
      entirely, since Playwright does not yet support testing Firefox
      extensions[2]. To test the MV2 code via the integration tests,
      using the chrome-mv2 build is the best we can do for now.

1 - https://developer.chrome.com/blog/resuming-the-transition-to-mv3/
2 - microsoft/playwright#7297
kzar added a commit to kzar/duckduckgo-privacy-extension that referenced this issue May 1, 2024
…tion

We are migrating Chrome extension users over onto the manifest
v3 (MV3) build, in time for the June deadline[1]. Once that's
finished, only Firefox users will remain on the MV2 build. Let's
rename the build, release, and test scripts and related documentation
to reflect that change.

Note: We unfortunately can't remove the chrome-mv2 build target
      entirely, since Playwright does not yet support testing Firefox
      extensions[2]. To test the MV2 code via the integration tests,
      using the chrome-mv2 build is the best we can do for now.

1 - https://developer.chrome.com/blog/resuming-the-transition-to-mv3/
2 - microsoft/playwright#7297
@s-c-p
Copy link

s-c-p commented May 2, 2024

+1 (python)

kzar added a commit to duckduckgo/duckduckgo-privacy-extension that referenced this issue May 2, 2024
…tion (#2524)

We are migrating Chrome extension users over onto the manifest
v3 (MV3) build, in time for the June deadline[1]. Once that's
finished, only Firefox users will remain on the MV2 build. Let's
rename the build, release, and test scripts and related documentation
to reflect that change.

Note: We unfortunately can't remove the chrome-mv2 build target
      entirely, since Playwright does not yet support testing Firefox
      extensions[2]. To test the MV2 code via the integration tests,
      using the chrome-mv2 build is the best we can do for now.

1 - https://developer.chrome.com/blog/resuming-the-transition-to-mv3/
2 - microsoft/playwright#7297
@siddharth2023
Copy link

Much needed feature!!

@ezexe
Copy link

ezexe commented May 6, 2024

would be awesome

@JackYouk
Copy link

+1 (python)

@3droj7
Copy link

3droj7 commented Jul 4, 2024

This one should be great! (python)

@harel-tussi
Copy link

would be great to have this

@jvbriones
Copy link

much needed - thanks!

@trossr32
Copy link

trossr32 commented Sep 2, 2024

Another upvote for this. It would also be great if Firefox add-ons for android could be tested although I appreciate this is beyond the scope of this ticket.

@Mbaspfd
Copy link

Mbaspfd commented Sep 5, 2024

+1

@ChristopherBull
Copy link

Yes, please.

@siddharth2023
Copy link

+1

@crellison
Copy link

+1

1 similar comment
@rjb-tech
Copy link

+1

@Frederick-Hughes
Copy link

We need this! Thanks

@OtuzgenJC
Copy link

would be great to have 🚀

@StiliyanKushev
Copy link

Bump, please!

@evandor
Copy link

evandor commented Nov 27, 2024

upvoting, would be very helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests