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

feat (cli) Added Brave Browser debugger support #25109

Merged
merged 6 commits into from
Nov 8, 2023
Merged

Conversation

kapobajza
Copy link
Contributor

Why

I wanted to debug my app using Brave Browser, but I couldn't. So I decided to add support for it.

How

By extending the LaunchBrowser and LaunchBrowserImpl functionalities.

Test Plan

  • Wrote some tests.
  • Also built the CLI and tried it locally by starting a new metro bundler using my local build, and then starting the debugger from the metro bundler (by pressing "j")

Checklist

@expo-bot expo-bot added the bot: suggestions ExpoBot has some suggestions label Oct 30, 2023
@EvanBacon EvanBacon requested a review from Kudo October 30, 2023 20:28
Copy link
Contributor

@Kudo Kudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for bringing this great pr. i'm leaving some comments and will need to test brave on windows and linux before merging it.

@@ -15,6 +19,21 @@ export interface MetroInspectorProxyApp {

let openingBrowserInstance: LaunchBrowserInstance | null = null;

const IS_WSL = require('is-wsl') && !require('is-docker')();

function createBrowser() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you share the insight why you would like to move the internal createBrowser from LaunchBrowser.ts to JsInspector.ts?

Copy link
Contributor Author

@kapobajza kapobajza Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved createBrowser to JSInspector.ts because createBrowser was only being used in LaunchBrowser.ts. So I could have exported createBrowser from LaunchBrowser.ts or just move it to JSInspector.ts. The former made more sense to me. Nevertheless, if the latter makes more sense I can adjust the changes accordingly.

And I did all of that just to to inject a LaunchBrowserImpl instance into the launchBrowserAsync function and make it testable. Yeah, sure, I could've used jest.mock instead, but I am not fond of jest.mock and I find this to be the safer way. But if using jest.mock suits this project more, I could also do that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, i think exporting createBrowser makes more sense and also helps LaunchBrowser.ts isolated.

Our test target would then change to createBrowser and we coud also move the logic here into the createBrowser.

for (const browserType of [LaunchBrowserTypes.CHROME, LaunchBrowserTypes.EDGE]) {
const isSupported = await browser.isSupportedBrowser(browserType);
if (isSupported) {

does that sound good to you?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've understood the first part and I'll export the createBrowser function from LaunchBrowser.ts.

But I am not entirely sure what you mean by the second part: to move the browser is supported check to the createBrowser function. You mean you want to check if the browser is supported, before returning the LaunchBrowserImpl instance from createBrowser? Something like:

export async function createBrowserAsync(
  platform: NodeJS.Platform,
  supportedBrowsers: LaunchBrowserTypes[]
) {
  let browserImpl: LaunchBrowserImpl | undefined = undefined;

  if (platform === 'darwin') {
    browserImpl = new LaunchBrowserImplMacOS();
  }
  if (platform === 'win32' || IS_WSL) {
    browserImpl = new LaunchBrowserImplWindows();
  }
  if (platform === 'linux') {
    browserImpl = new LaunchBrowserImplLinux();
  }

  if (browserImpl === undefined) {
    throw new Error('[LaunchBrowser] Unsupported host platform');
  }

  let supportedBrowsersCount = 0;

  for (const browserType of supportedBrowsers) {
    const isSupported = await browserImpl.isSupportedBrowser(browserType);
    if (isSupported) {
      supportedBrowsersCount++;
    }
  }

  if (supportedBrowsersCount === 0) {
    throw new Error(
      `[LaunchBrowser] Unable to find a browser on the host to open the inspector. Supported browsers: ${supportedBrowsers.join(
        ', '
      )}`
    );
  }

  return browserImpl;
}

If this is what you meant, then I will still have to loop over the supportedBrowsers array inside of LaunchBrowser:

for (const browserType of [LaunchBrowserTypes.CHROME, LaunchBrowserTypes.EDGE]) {
const isSupported = await browser.isSupportedBrowser(browserType);
if (isSupported) {
return browser.launchAsync(browserType, launchArgs);
}
}

In order to call browser.launchAsync with the browserType argument.

I have a feeling that I misunderstood you.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry i didn't describe it clearly. let's show the code directly: https://github.com/expo/expo/compare/%40kudo/pr-25109

if there's still any unclear part, please feel free to let me know.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is clear now. Thank you for the clarification and your code.
I rebased to your branch.

@expo-bot expo-bot added bot: passed checks ExpoBot has nothing to complain about and removed bot: suggestions ExpoBot has some suggestions labels Oct 31, 2023
Copy link
Contributor

@Kudo Kudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for helping that. i've got a chance to test brave on linux and windows. please help to revise the launch id accordingly.

Copy link
Contributor

@Kudo Kudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's ready to go. thanks again for the awesome work.

@Kudo Kudo merged commit 0b0a67b into expo:main Nov 8, 2023
2 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: passed checks ExpoBot has nothing to complain about
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants