Commit Graph

62 Commits

Author SHA1 Message Date
Andrey Goncharov
cc76a21d80 Add more tracking data for UI startup
Reviewed By: lblasa

Differential Revision: D50365803

fbshipit-source-id: b6a601e7bf987738400a86be6814de7cafd50d3d
2023-10-17 08:28:02 -07:00
Lorenzo Blasa
17103ce1fa If failure, track client type
Summary: Add client type information to client errors

Reviewed By: aigoncharov

Differential Revision: D50365929

fbshipit-source-id: f1544b3974c5dfa4fc9b3b6229d6ebb6334dc0d9
2023-10-17 08:05:53 -07:00
Andrey Goncharov
ee7736caee Add a more complex logger to Flipper UI Browser
Reviewed By: passy, lblasa

Differential Revision: D50223987

fbshipit-source-id: 108e1753b555c7d7b32d3fc2408c2f8efcbadb4d
2023-10-16 09:27:50 -07:00
Lorenzo Blasa
fe7a839b14 TokenProvider can fail if the server is offline
Summary: If the server is offline, the fetch request will fail and this was not properly handled.

Reviewed By: antonk52

Differential Revision: D50299455

fbshipit-source-id: dab8336dedaf93db049dc703a23f9e33935212be
2023-10-15 12:57:59 -07:00
Lorenzo Blasa
db4d15ed05 URL and Token provider
Summary:
Use an URLProvider paired with a token provider for attempts to establish a websocket connection.

This gives extra flexibility whenever a token is not available or changes as the ReconnectingWebSocket will call the URLProvider after each unsuccessful connection.

Reviewed By: antonk52

Differential Revision: D50220329

fbshipit-source-id: f53993a90c9c0f64bf213019b6b8af5fa818048d
2023-10-12 04:29:13 -07:00
Anton Kastritskiy
2edcb29e46 Back out "ESM plugin bundles"
Summary:
Original commit changeset: 2a60315dd5c0

Original Phabricator Diff: D50015827

Reviewed By: lblasa

Differential Revision: D50168201

fbshipit-source-id: 3430c37b0aa6a5e3a5ec35fb4c54f01899236173
2023-10-11 04:21:54 -07:00
Anton Kastritskiy
9f22952ef2 Back out "fallback to handle plugins as commonjs if dynamic import fails"
Summary:
Original commit changeset: edef9999ad44

Original Phabricator Diff: D50081726

Reviewed By: passy, lblasa

Differential Revision: D50168200

fbshipit-source-id: ba96101bc63409af8ec81857efa81e5aeeb0e3cb
2023-10-11 04:21:54 -07:00
Anton Kastritskiy
5a5a509d4d fallback to handle plugins as commonjs if dynamic import fails
Summary: This should help us to make flipper more reliable and avoid failing loading plugins if they are loaded from cache(old ones)

Reviewed By: lblasa

Differential Revision: D50081726

fbshipit-source-id: edef9999ad44660331153a082e15c6f3f5de9b05
2023-10-10 03:37:21 -07:00
Anton Kastritskiy
c4a1c90a1e ESM plugin bundles
Summary:
This change will allow us to display correct stack traces in flipper UI as well as send them to scuba.

Currently correct stack traces are only displayed in the console and we do not have access to them.

Reviewed By: ivanmisuno

Differential Revision: D50015827

fbshipit-source-id: 2a60315dd5c06b2635ce0414f612ff1fdca0e489
2023-10-10 03:37:21 -07:00
Lorenzo Blasa
f11052cffd Log if token is obtained from manifest
Summary: ^

Reviewed By: antonk52

Differential Revision: D50004785

fbshipit-source-id: c8809c1ff5b6b32722e9df2d7e4002be533f615d
2023-10-06 03:26:14 -07:00
Lorenzo Blasa
541570c8ab Add client logs for different stages
Summary: ^

Reviewed By: antonk52

Differential Revision: D49973541

fbshipit-source-id: 3bac97fb22586cc49e74dd5deceeb5310a1385bc
2023-10-05 22:42:37 -07:00
Lorenzo Blasa
d9ad2a8932 Remove troubleshoot from here
Summary:
Simplify how messages (state updates) are shown in Flipper UI.

This main change was introduced as a way to show the 'Start' server button whenever we were in a disconnected state. This is not as simple as the server may be restarting or the client may be even have reset the WS connection. Hence you the experience where this UI is shown and immediately dismissed.

This UI is only ever shown if at one point the server was alive, period. So, in this case, either the server becomes available again OR the user quits the PWA/tab/browser and launches again.

IMHO, this is a better experience that totally assuming the server is dead.

In a next iteration, we can be more clever and have a timeout such that if after a set period of time the server doesn't become online, then we show a button to start (or force kill) the server.

Reviewed By: aigoncharov

Differential Revision: D49915698

fbshipit-source-id: 03fcc150ed1f1303d1d727c82a71eb32616208e8
2023-10-05 04:37:16 -07:00
Lorenzo Blasa
f1c88a464b Do not use window reload
Summary: Let's keep it simple, do not reload. Just show/hide the right content.

Reviewed By: antonk52

Differential Revision: D49377316

fbshipit-source-id: 9b2a47374da3e72f17e2d55c9290960b703fd43e
2023-09-18 12:03:09 -07:00
Lorenzo Blasa
342ef42114 Break connection loop
Summary:
Whenever there was a connectivity error, we would show an error message and setup a retry mechanism as to refresh the page as to make it transparent for engineers to have a working workspace again.

The problem is that there are two different channels:
- HTTP server
- WS server

If the HTTP server is healthy but there is a WS error, it is not entirely correct to try to reload the page. If the error conditions for the WS remain, then we end up in a loop.

Reviewed By: passy, antonk52

Differential Revision: D49373335

fbshipit-source-id: 4e0a08fe2384860db0bf92a22edc87402d41651c
2023-09-18 08:57:15 -07:00
Lorenzo Blasa
0128ea00ec Restart/shutdown when settings are applied
Summary: Shutdown flipper server whenever a restart is required.

Reviewed By: antonk52

Differential Revision: D49369884

fbshipit-source-id: 62d8aa9dd58408dc351617bb09df4509a819ab2f
2023-09-18 07:42:36 -07:00
Lorenzo Blasa
25e187bf41 Restart message improvement
Summary:
There's no notion of restarting Flipper when running as a PWA.

In the meantime, update the advise message we give to engineers as to wait 30 seconds before attempting to relaunch (Flipper server keeps running in the background for 30 seconds after quitting)

Reviewed By: antonk52

Differential Revision: D49369707

fbshipit-source-id: 9451265f8941e457e734d1cb0ea74a0dea492b88
2023-09-18 06:17:50 -07:00
Lorenzo Blasa
9e219b07d8 Fix Loading page
Summary:
The existing loading page was not behaving the way it was intended. The previous implementation triggered a page reload which made the whole retry mechanism useless.

Instead, a new endpoint was defined to expose whether the server is ready or not. Use this instead as a way of knowing whether we are good to reload the page.

Reviewed By: passy

Differential Revision: D49314749

fbshipit-source-id: eb67765d7deab8610fa5d31e710070da43a18c1c
2023-09-15 05:29:40 -07:00
Lorenzo Blasa
2b4c631652 Certificate and token generation fixes
Summary:
A few things need to be done which are on this change:

- Certificate generation should execute as an atomic operation, hence, it needs to be synchronised.
- Do not generate client token as part of certificate generation. This causes a deadlock now.
- Add more logs for troubleshooting

Reviewed By: aigoncharov

Differential Revision: D49269624

fbshipit-source-id: 071a8e5b895198730b7d914cc4622837e9094e2f
2023-09-14 04:15:18 -07:00
Lorenzo Blasa
c0347ec830 Deep-link hooked to our protocol handler
Summary: This hooks the PWA deep-link to our existing deep-link url handler.

Reviewed By: antonk52

Differential Revision: D48598886

fbshipit-source-id: 8da9b7bc89bebdafc2bd4c0dc0bd7608864e0254
2023-08-24 07:25:01 -07:00
Lorenzo Blasa
aa327b1a46 Deep-link scaffolding
Summary:
This change adds the necessary scaffolding to enable deep-link for PWA.

1. Registers the protocol/scheme in the manifest.json
2. Add a skeleton handler that parses the received arguments

Notes for reviewers:

PWA cannot reuse the 'flipper://' scheme as is not allowed. PWA schemes are limited. The only extension point is 'web+...' which is the one that is used.

Reviewed By: antonk52

Differential Revision: D48562301

fbshipit-source-id: e191fcb1a6604d20a55c1acdadf6a8eb0194895b
2023-08-24 07:25:01 -07:00
Lorenzo Blasa
4ff9279a0b Offline troubleshoot when server disconnects
Summary:
If there server disconnects, we used to show a red box message on the lower left section of the screen. It didn't say much other than the server had disconnected.
If you are aware of what the server is, then you may try to manually restart it.

Instead of doing that, a much better experience is to show the no connection troubleshoot with the button to start the server or with instructions on how to achieve this.

Reviewed By: antonk52

Differential Revision: D48467308

fbshipit-source-id: 0ffded95789c7548d9f1e1a9127409e02e72ab8c
2023-08-18 07:59:51 -07:00
Lorenzo Blasa
ce13ee426f Open file import
Summary: This change only adds the PWA as capable of handling files with the ".flipper" extension.

Reviewed By: aigoncharov

Differential Revision: D48353437

fbshipit-source-id: fd78942ac4dffb7d26d5ca5be826290018465b93
2023-08-17 13:46:08 -07:00
Lorenzo Blasa
b45eed0e9a 'Capture' cancel on file import
Summary:
There's no explicit way of knowing if the file selection dialog was dismissed/canceled without a selection.

Instead, subscribe once to the windows focus event, as it will the event will be received when this happens.

Reviewed By: antonk52

Differential Revision: D48434187

fbshipit-source-id: dd20c55885bb3ef6bef423e17a2606d71ede288d
2023-08-17 08:57:55 -07:00
Lorenzo Blasa
ff6f98fc0d Import File implementation
Summary: Implementation was missing for the browser. This provides a default implementation.

Reviewed By: aigoncharov

Differential Revision: D48311198

fbshipit-source-id: fd067600f571234e0fbccfb90853b62f175ff8fb
2023-08-14 11:33:06 -07:00
Lorenzo Blasa
daa3a38ed3 Flipper export file implementation
Summary:
^

Changelog: add export file implementation for browsers

Reviewed By: antonk52

Differential Revision: D46840341

fbshipit-source-id: 8a011f2a7c0ce329286cb8813def8f9c0572d133
2023-06-19 08:33:54 -07:00
Lorenzo Blasa
2815ba0fb8 Copy/Paste implementation
Summary: ^

Reviewed By: aigoncharov

Differential Revision: D46515194

fbshipit-source-id: 0ee6931569d5248d5643b391683e230e0c095e41
2023-06-07 06:04:46 -07:00
Lorenzo Blasa
c6d5eb3334 Flipper as PWA
Summary:
^

Reference: https://docs.google.com/document/d/1flQJUzTe4AuQz3QCpvbloQycenHsu7ZxbKScov7K7ao

Reviewed By: passy

Differential Revision: D45693382

fbshipit-source-id: 5a2e6c213a7e7e2cf9cd5f3033cff3e5291a2a92
2023-05-16 04:32:47 -07:00
Lorenzo Blasa
238f40f55d Mandate auth token to connect over TCP
Summary:
Until now, launching flipper-server with TCP would accept any incoming connection as long as it comes from the same origin (localhost) using web socket host origin verification.

This is not entirely secure as origin can be spoofed with tools like curl.

Our team created a security review and a proposal was written:
https://docs.google.com/document/d/16iXypCQibPiner061SoaQUFUY9tLVAEpkKfV_hUXI7c/

Effectively, Flipper can generate a token which is then used by the client to authenticate.

This diff contains the changes required to generate, obtain, and validate authentication tokens from clients connecting to flipper over TCP connections.

The token itself is a JWT token. JWT was chosen because it is a simple industry standard which offers three features which can immediately benefit us:

- Expiration handling. No need for Flipper to store this information anywhere.
- Payload. Payload can be used to push any data we deem relevant i.e. unix username.
- Signing. Signed and verified using the same server key pair which is already in place for certificate exchange.

Additionally, the token is stored in the Flipper static folder. This ensures that the browser and PWA clients have access to it.

Reviewed By: mweststrate

Differential Revision: D45179654

fbshipit-source-id: 6761bcb24f4ba30b67d1511cde8fe875158d78af
2023-05-05 07:52:13 -07:00
Lorenzo Blasa
2583a076c0 Delete unused code
Summary:
^

There's no references to this anywhere, so delete.

Reviewed By: antonk52

Differential Revision: D45309041

fbshipit-source-id: e62e94b089eee30b82b05f64c8e7b31dd03597b6
2023-04-26 04:42:43 -07:00
Andrey Goncharov
226ccf91f6 Create flipper-server-client package
Summary:
FlipperServerClient is a useful abstraction for any JS-based client of headless Flipper. No need to bundle it with flipper-frontend-core, as the rest is not useful for external clients.
Currently, I am planning to add it to jest-e2e to send commands to Flipper

Reviewed By: lblasa

Differential Revision: D40765668

fbshipit-source-id: af48710bb15444ac1ecd649fe9a2ab252f3088f3
2022-10-31 04:26:43 -07:00
Lorenzo Blasa
587f428cf8 Allow plugins to use css
Summary:
Flipper plugins fail when importing css from third-party dependencies. This diff tries to fix that.

Effectively, the plugin can import the css and export it when is bundled.

When we load the plugin, we check if there's a css file for it. If there's one, we return it and try to use it.

Reviewed By: aigoncharov

Differential Revision: D40758178

fbshipit-source-id: e53afffcc481504905d5eeb1aea1f9114ee2a86b
2022-10-27 22:50:30 -07:00
Andrey Goncharov
982193df48 Fix plugin source maps in dev mode
Summary:
Start bundling source maps together with the source code itself in the dev mode. Therefore it is no longer required to add a link to the external source map file in dev mode.
In prod mode we still ship them separately.

Reviewed By: mweststrate

Differential Revision: D39775064

fbshipit-source-id: 6c56df7a3fce084c07a8618a63dbd8ae4741348c
2022-09-26 06:54:03 -07:00
Andrey Goncharov
3314c77ce9 Add exportFileBinary to FlipperLib
Reviewed By: antonk52

Differential Revision: D39692937

fbshipit-source-id: 7b3c78d004a9734cd8ae660d5782be1f02c00009
2022-09-21 09:26:19 -07:00
Andrey Goncharov
8716761cb3 Fix require monkey-patching in electron build
Summary:
In D39311893 (094c5bdfdd) we started monkey-patching `require` to resolve global dependencies in the plugins. Apparently, patching `globalThis.require` did not work in the electron env. On my local machine it kept working because I had the experimental `flipper-server` feature enabled which embeds flipper-server into the electron build. In flipper-server we properly patch `require` via `Module.prototype.require` which affected the global require in electron.
With this fix we now properly patch require in electron via Module.prototype.require all the time

Changelog: Fix plugin loading with experimental flipper-server disabled

Reviewed By: nikoant

Differential Revision: D39633821

fbshipit-source-id: 9554f643c625620d116075ae87f573d8447850f6
2022-09-20 01:36:56 -07:00
Andrey Goncharov
642a3ebf81 Remove default plugin entrypoints for hot-reloading
Summary: As we stopped bundling plugins in D39276249, we no longer need the entry points for the bundled plugins (these entry points are always going to be empty)

Reviewed By: lblasa

Differential Revision: D39307565

fbshipit-source-id: 43751fe31c8bd962677c226b27cfe52093d3f2d4
2022-09-15 10:02:19 -07:00
Andrey Goncharov
dcbc7c40bb Stream server logs to browser
Summary: Makes Flipper Logs tab functional for Flipper Browser

Reviewed By: lblasa

Differential Revision: D37459924

fbshipit-source-id: 4ebf3d47fbbf90bb367e01986b12dec782b03c34
2022-06-28 06:27:43 -07:00
Lorenzo Blasa
23b551c8bf Host and port as function args
Summary:
^

Before this change, the client assumed the host and port came from location.host which is fine on the browser.

In all other cases, that object/properties may be undefined.

As such, add host and port as function args and use that instead.

Reviewed By: passy

Differential Revision: D36440423

fbshipit-source-id: 5f931f1d610d583db6a2e549e1213585f0d03dee
2022-05-17 04:20:30 -07:00
Lorenzo Blasa
bfcdb82b43 Move flipper-server client to flipper-frontend-core
Summary: ^

Reviewed By: aigoncharov

Differential Revision: D36410944

fbshipit-source-id: 2adb5904cd0f5f15d08be22c611d6774e7533f94
2022-05-17 03:54:16 -07:00
Pascal Hartig
3032736294 Fix type errors for flipper-server and flipper-ui-browser
Summary:
Before:

```
flipper-server/src/startBaseServer.tsx(222,30): error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
  Type 'undefined' is not assignable to type 'string'.
flipper-ui-browser/src/flipperServerConnection.tsx(25,9): error TS2322: Type 'Timeout' is not assignable to type 'number'.
```

Reviewed By: nikoant

Differential Revision: D36100188

fbshipit-source-id: 1913a43109a0e068394a188d362f6a9e473e7904
2022-05-03 09:55:04 -07:00
Andrey Goncharov
f85def32fb Migrate from socket.io
Reviewed By: passy

Differential Revision: D34787674

fbshipit-source-id: 63d7c166ea29d14c96f0646a045e3f6fa93472e2
2022-03-10 10:31:24 -08:00
Anton Kastritskiy
c5dd1fc350 rename files from ts to tsx in flipper-* packages
Summary: mass files rename

Reviewed By: nikoant

Differential Revision: D33890252

fbshipit-source-id: d5afaa60af7340313a97d8e4967fe37f00abd9db
2022-01-31 10:16:19 -08:00
Andres Suarez
79023ee190 Update copyright headers from Facebook to Meta
Reviewed By: bhamodi

Differential Revision: D33331422

fbshipit-source-id: 016e8dcc0c0c7f1fc353a348b54fda0d5e2ddc01
2021-12-27 14:31:45 -08:00
Michel Weststrate
54dacb7e5d Make sure icons are bundled
Summary: Make sure icons are prefetched for flipper-server prod builds, like we do for electron, so that the user doesn't need an internet connection to see icons

Reviewed By: nikoant

Differential Revision: D33296389

fbshipit-source-id: bfa92d78d8d77030238e5cca10d7aa6dcfb88e8b
2021-12-24 02:16:48 -08:00
Michel Weststrate
72fa481d27 Fix generation of bundled.json, make source maps work in prod builds
Summary:
This diff fixes several issues around loading plugin, such as:

* make suresource maps work in the flipper-server production build
* make sure default plugins are no symlinked, which wouldn't work anywhere else but on the the system where it was build
* support release channel param for flipper-server

Bundled flipper-server is now 42MB (with icons (see later diffs) and plugins
```
ll flipper-server-v0.0.0.tgz
-rw-r--r--  1 mweststrate  staff    42M 23 Dec 15:29 flipper-server-v0.0.0.tgz
```

Reviewed By: nikoant

Differential Revision: D33294677

fbshipit-source-id: 63538dc8127f883fee6a3608673ad11ce239b350
2021-12-24 02:16:48 -08:00
Michel Weststrate
b1d960e4c4 Make sure plugin loading works in NPX builds
Summary: Make sure non-bundled plugins load correctly . Note that sourcemaps don't load yet

Reviewed By: nikoant

Differential Revision: D33278639

fbshipit-source-id: 9951286ec6df65f33149e4687261a43e6c072c31
2021-12-24 02:16:48 -08:00
Michel Weststrate
cea7be7fde Clean up globals
Summary: This diff is some boyscouting on cleaning up our globals, and stop using them inconsistently icmw global or window

Reviewed By: aigoncharov

Differential Revision: D33171108

fbshipit-source-id: 400893e5f31523631a7ab6fda428524c751901f1
2021-12-17 10:04:23 -08:00
Michel Weststrate
5df34a337c Unshare global types
Summary:
This diff adds `types` fields on the compiler config for every project. This way we can make sure that for example node types and packages are not available in flipper-ui-core. Without an explicit types field, all types would be shared between all packages, and implicitly included into the compilation of everything. For the same reason `types/index.d.ts` has been removed, we want to be intentional on which types are being used in which package.

This diff does most of the work, the next diff will fine tune the globals, and do some further cleanup.

As an alternative solution I first tried a `nohoist: **/node_modules/types/**` and make sure every package list explicitly the types used in package json, which works but is much more error prone, as for example two different react types versions in two packages will cause the most unreadable compiler error due to the types not being shared and not literally the same.

Reviewed By: lawrencelomax

Differential Revision: D33124441

fbshipit-source-id: c2b9d768f845ac28005d8331ef5fa1066c7e4cd7
2021-12-17 07:36:07 -08:00
Michel Weststrate
78413c1ecf Register shortcuts on window instead of globally
Summary:
Changelog: Register shortcuts only for Flipper application instead of globally. Fixes https://github.com/facebook/flipper/issues/3090

As reported, during decapitation we accidentally started registering shortcuts globally, rather per app as it used to be in the menu's. This diff fixes that and also makes sure shortcuts are supported in the browser version of flipper

Reviewed By: lawrencelomax

Differential Revision: D33158445

fbshipit-source-id: 8371e5b96e772152eeb93ba990e1f5edb9e67085
2021-12-16 14:51:08 -08:00
Michel Weststrate
5ce5d897c8 Make loading of bundled plugins working and robust
Summary:
Bundled plugins so far didn't load because the defaultPlugins was not generated yet. Fixed follow up errors that resulted from node modules not being available in the browser, and made the process more robust so that one plugin that fails to initialise doesn't kill all bundled plugins from being loaded.

Cleaned up the server scripts, and reused the BUILTINS list that is already maintained in the babel transformer.

Report errors during the build process if modules are referred that are stubbed out (later on we could maybe error on that)

Reviewed By: aigoncharov

Differential Revision: D33020243

fbshipit-source-id: 3ce13b0049664b5fb19c1f45f0b33c1d7fdbea4c
2021-12-13 05:48:17 -08:00
Michel Weststrate
ac9080abac Remove 'process' usage
Summary: Removed process, adbkit and electron usages that were still remaining. Verified changes by disabling the built-in module stubbing (will be cleaned up further later in this stack).

Reviewed By: aigoncharov

Differential Revision: D33019083

fbshipit-source-id: 8bfce31f4b5ed349cb4fd86d34c9b41b9b8b8360
2021-12-13 05:48:17 -08:00