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(trace-viewer): embedded mode support PoC #30885

Merged
merged 2 commits into from
Jun 28, 2024

Conversation

ruifigueira
Copy link
Contributor

This comment has been minimized.

This comment has been minimized.

@pavelfeldman
Copy link
Member

I'm supportive for those, let me know when they are no longer drafts!

@ruifigueira ruifigueira marked this pull request as ready for review May 21, 2024 19:56
@ruifigueira
Copy link
Contributor Author

ruifigueira commented May 21, 2024

@pavelfeldman I removed the draft, but this is still a very basic implementation just to check if the integration was possible.

I found out some issues with this approach: when the trace viewer iframe gets the focus keyboard shortcuts stop working, and I ned to click outside it to open the command palette for instance.

@ruifigueira ruifigueira force-pushed the feat/embedded-trace-viewer branch 2 times, most recently from 71029da to 216aedb Compare May 22, 2024 22:12

This comment has been minimized.

@pavelfeldman
Copy link
Member

I found out some issues with this approach: when the trace viewer iframe gets the focus keyboard shortcuts stop working, and I ned to click outside it to open the command palette for instance.

That's unfortunate! I was rendering webviews in vscode w/o such issues. Is iframe w/ snapshot breaking it? How is service worker doing, are snapshots rendered fine?

@ruifigueira
Copy link
Contributor Author

ruifigueira commented May 22, 2024

I tried to render the trace viewer html directly without iframe and service worker doesn't work there. Nevertheless, we can just rely on the running server instead of the service worker. The only thing I still need to figure out is on how to make the websocket work, or if not possible, on how to emulate it.

@pavelfeldman
Copy link
Member

we can just rely on the running server instead of the service worker.

Unfortunately, we can't. It is essential for SW to fulfill all the requests.

@ruifigueira
Copy link
Contributor Author

I am figuring that out the hard way :( I was doing some quick and dirty tests and deactivated the sw to rely on the webserver. I thought it was already handling trace requests as a fallback, but it was not, so I had to copy & paste the service worker logic there with necessary adjustments for it to work, but I stumbled on cross-domain snapshot resources that are handled by the sw and I don't see a way out of that...

I'll go back to the iframe solution and see if there's a workaround for it.

@ruifigueira
Copy link
Contributor Author

Problem explained here, with a workaround proposal:

microsoft/vscode#65452 (comment)

@ruifigueira
Copy link
Contributor Author

That did the trick, key bindings are triggered as expected when trace viewer is focused

This comment has been minimized.

@@ -39,5 +39,26 @@ import { WorkbenchLoader } from './ui/workbenchLoader';
setInterval(function() { fetch('ping'); }, 10000);
}

if (window.parent !== window && new URL(window.location.href).searchParams.has('embedded')) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we do this when we are building the content for the trace viewer instead in the extension instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunatelly no, because this code must run inside the iframe. But maybe create an embedded.html / embedded.tsx, similar to index.tsx and uiMode.tsx, we can just drop this code there as well as instanciating the parameterized WorkbenchLoader

Copy link
Member

Choose a reason for hiding this comment

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

Unfortunatelly no, because this code must run inside the iframe.

I understand that the snapshot renderer should run in an iframe, but the app itself does not have to. Are you doing this for convenience?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The app depends on the SW, and for that reason there's no easy way to render it without the iframe because webviews don't support SW

packages/trace-viewer/src/ui/workbenchLoader.tsx Outdated Show resolved Hide resolved

This comment has been minimized.

@ruifigueira
Copy link
Contributor Author

The snapshot popout link is not working (window.open doesn't work in vscode). Using vscode.env.openExternalUrl does not work either because it won't share the sw.

We can either disable it (it will still work on non-embedded mode) or delegate it to the server (for instance, it can launch a playwright-controlled browser and inject the trace file for sw to load it before opening the snapshot.html URL).

@ruifigueira
Copy link
Contributor Author

I found out why I thought I needed to inject the trace file before opening snapshot.html. It's a bug: #31033

This comment has been minimized.

This comment has been minimized.

@@ -24,7 +24,8 @@ import { Workbench } from './workbench';
import { TestServerConnection } from '@testIsomorphic/testServerConnection';

export const WorkbenchLoader: React.FunctionComponent<{
}> = () => {
embedded?: boolean
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
embedded?: boolean
supportTraceDrop?: boolean

Copy link
Contributor Author

Choose a reason for hiding this comment

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

embedded mode only hides the trace viewer header, so maybe call it hideHeader instead?

ruifigueira added a commit to ruifigueira/playwright-vscode that referenced this pull request Jun 11, 2024
Depends on microsoft/playwright#30885 being merged and @playwright/test being updated

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

@ruifigueira
Copy link
Contributor Author

ruifigueira commented Jun 24, 2024

Quick status on this:

  • the implementation with trace viewer rendered in iframe seems stable. and I added some tests on playwright-vscode side
    • until now, the only drawback I found was the key binding issue, which I "fixed" with this workaround
  • I added a setting to enable / disable embedded mode. Besides, embedded mode is only active if playwright version supports it
  • embedded mode no longer requires that playwright server is launched with 0.0.0.0 when running remotely, because vscode performs local port forwarding
  • embedded mode also works with devcontainers, remote SSH and codespaces

I also tried once again to implement it without the iframe (the issues I stumbed when I first tried it were mostly caused by #31033. Even if not stable yet, I'm already confident that is possible to do it. It adds some complexity, though, because playwright server needs to serve trace resources just like service worker (we cannot rely on service worker when not rendering the trace viewer on an iframe, as explained before). You can find its current implementation here:

Let me know your thoughts if it's worth to go with this solution, or if the iframe solution is good enough.

@chensce
Copy link

chensce commented Jun 25, 2024

the iframe solution is good enough

@chensce
Copy link

chensce commented Jun 25, 2024

look forward for inspect(code gen) embedded mode

@chensce
Copy link

chensce commented Jun 25, 2024

record embedded mode

@ruifigueira
Copy link
Contributor Author

@chensce this is for trace viewer only, no recorder functionality is covered here, for that you already have the vscode recorder.

@pavelfeldman
Copy link
Member

pavelfeldman commented Jun 25, 2024

Let me know your thoughts if it's worth to go with this solution, or if the iframe solution is good enough.

Ok, let's try the iframe solution.

Looking at the code, I think we can improve the situation via untangling some of the existing complexities. Here is my thinking:

  • Modern VS Code extension and UI Mode share the same testServer and communicate over the same wire, basically there is a lot of code reuse where either UI Mode or VS Code extension is the front-end working against the same server code.
  • This server is actually inherited from trace viewer - TestServer.start calls startTraceViewerServer.
  • When VS Code extension finds a Playwright config, it starts a server for it and uses it to list files, tests, etc. This means that you already have a trace viewer server running that can serve static files and load traces.
  • The live mode won't work because TraceViewer opened against test server won't have onLoadTraceRequested triggered - that is usually wired via the stdin in a standalone mode. But you can trigger it manually via sending a message to embedded.tsx.
  • In the longer run, I don't think you should reuse WorkbenchLoader in embedder.tsx and rather use Workbench instead. There will be some code duplication, but it'll make it clear that embedder is using one way to load live traces and the standalone more would use another way. Think about it this way, we'll have:
    • UI mode app
    • Trace Viewer app
    • Trace Viewer with StdIn app (external Trace viewer when used from VS Code extension)
    • Embedder app (to use in a web view in VS Code extension)

@ruifigueira
Copy link
Contributor Author

  • The live mode won't work because TraceViewer opened against test server won't have onLoadTraceRequested triggered - that is usually wired via the stdin in a standalone mode. But you can trigger it manually via sending a message to embedded.tsx.
  • In the longer run, I don't think you should reuse WorkbenchLoader in embedder.tsx and rather use Workbench instead.

I was already addressing those two points in the EmbeddedWorkbenchLoader in my non-iframe alternative, I'll cherry-pick those changes.

@pavelfeldman
Copy link
Member

I was already addressing those two points in the EmbeddedWorkbenchLoader in my non-iframe alternative, I'll cherry-pick those changes.

You can keep it as an iframe at first, to make changes more local.

ruifigueira added a commit to ruifigueira/playwright-vscode that referenced this pull request Jun 26, 2024
Depends on microsoft/playwright#30885 being merged and @playwright/test being updated
@ruifigueira
Copy link
Contributor Author

ruifigueira commented Jun 26, 2024

I just updated this and vscode PRs to accomodate your suggestions. Reusing the testServer was a great tip, it simplifies a lot and it's one less process to manage.

This comment has been minimized.

Copy link
Member

@pavelfeldman pavelfeldman left a comment

Choose a reason for hiding this comment

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

A couple of nits and it is good to go.

packages/trace-viewer/src/embedded.tsx Outdated Show resolved Hide resolved
packages/trace-viewer/src/ui/embeddedWorkbenchLoader.tsx Outdated Show resolved Hide resolved
packages/trace-viewer/src/ui/popout.ts Outdated Show resolved Hide resolved
Copy link
Contributor

Test results for "tests 1"

7 flaky ⚠️ [chromium-library] › library/browsercontext-fetch-happy-eyeballs.spec.ts:49:3 › get should work on request fixture
⚠️ [chromium-library] › library/browsercontext-fetch-happy-eyeballs.spec.ts:49:3 › get should work on request fixture
⚠️ [chromium-library] › library/browsercontext-fetch-happy-eyeballs.spec.ts:49:3 › get should work on request fixture
⚠️ [firefox-library] › library/browsercontext-fetch-happy-eyeballs.spec.ts:49:3 › get should work on request fixture
⚠️ [chromium-library] › library/browsercontext-fetch-happy-eyeballs.spec.ts:49:3 › get should work on request fixture
⚠️ [webkit-library] › library/browsercontext-fetch-happy-eyeballs.spec.ts:49:3 › get should work on request fixture
⚠️ [playwright-test] › ui-mode-test-screencast.spec.ts:21:5 › should show screenshots

28400 passed, 655 skipped
✔️✔️✔️

Merge workflow run.

@pavelfeldman pavelfeldman merged commit 9bc45ea into microsoft:main Jun 28, 2024
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants