Skip to content

feat(devtools): implement iframe support#53934

Closed
AleksanderBodurri wants to merge 2 commits into
angular:mainfrom
AleksanderBodurri:devtools-iframe-support
Closed

feat(devtools): implement iframe support#53934
AleksanderBodurri wants to merge 2 commits into
angular:mainfrom
AleksanderBodurri:devtools-iframe-support

Conversation

@AleksanderBodurri

@AleksanderBodurri AleksanderBodurri commented Jan 16, 2024

Copy link
Copy Markdown
Member

Introduces Iframe support into Angular DevTools, see individual commits

@angular-robot angular-robot Bot added the detected: feature PR contains a feature commit label Jan 16, 2024
Comment thread devtools/projects/shell-browser/src/app/app.component.ts Outdated
Comment thread devtools/projects/shell-browser/src/app/app.module.ts Outdated
Comment thread devtools/projects/shell-browser/src/app/background.ts Outdated
Comment thread devtools/projects/shell-browser/src/app/content-script.ts Outdated
Comment thread devtools/projects/ng-devtools/src/lib/devtools.component.ts Outdated

@dgp1130 dgp1130 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for putting this together! Most of these comments are relatively minor.

I would love to see some automated tests here. There are a ton of if { return; } and null checks which comprehensive unit tests would help add a lot of confidence for. Is there anything we can do in that direction?

Comment thread devtools/projects/ng-devtools/src/lib/devtools-tabs/devtools-tabs.component.html Outdated
Comment thread devtools/projects/ng-devtools/src/lib/devtools.component.ts Outdated
Comment thread devtools/projects/ng-devtools/src/lib/devtools.component.html Outdated
Comment thread devtools/projects/ng-devtools/src/lib/devtools.component.html Outdated
Comment thread devtools/projects/ng-devtools/src/lib/devtools.component.ts Outdated
Comment thread devtools/projects/shell-browser/src/app/content-script.ts Outdated
Comment thread devtools/projects/shell-browser/src/app/content-script.ts Outdated
Comment thread devtools/projects/shell-browser/src/app/background.ts Outdated
Comment thread devtools/projects/shell-browser/src/manifest/manifest.chrome.json Outdated
Comment thread devtools/projects/shell-browser/src/manifest/manifest.chrome.json Outdated
Comment thread devtools/projects/ng-devtools/src/lib/devtools-tabs/devtools-tabs.component.html Outdated
@ngbot ngbot Bot added this to the Backlog milestone Jan 17, 2024
@AleksanderBodurri
AleksanderBodurri force-pushed the devtools-iframe-support branch 2 times, most recently from 35c7bc6 to a00d623 Compare January 18, 2024 08:38
Comment thread devtools/projects/ng-devtools/src/lib/devtools-tabs/devtools-tabs.component.ts Outdated
Comment thread devtools/projects/ng-devtools/src/lib/devtools.component.html Outdated
Comment thread devtools/projects/ng-devtools/src/lib/devtools.component.ts Outdated
Comment thread devtools/projects/shell-browser/src/app/background.ts Outdated
Comment thread devtools/projects/shell-browser/src/manifest/manifest.chrome.json Outdated
@AleksanderBodurri
AleksanderBodurri force-pushed the devtools-iframe-support branch 3 times, most recently from 289da20 to 6a9eb85 Compare January 19, 2024 21:23

@dgp1130 dgp1130 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for working through all these comments! It's definitely looking a lot cleaner. Looking forward to the tests for this PR.

Comment thread devtools/projects/ng-devtools/src/lib/application-operations/index.ts Outdated
Comment thread devtools/projects/ng-devtools/src/lib/devtools-tabs/devtools-tabs.component.html Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: I feel like we're repeating this logic in a few places. I wonder if we could move it into some kind of FrameManager.getSelectedFrame() function which would return the current frame or undefined if the top-level frame and warn / abort if multiple frames conflict? Basically a slightly more powerful version of the selectedFrame getter you already have.

It's a little awkward because undefined would be the top frame and also the case where there are multiple, so we might need a discriminated union there which adds complexity.

Related question: Do we need undefined to point at the top-level frame? Could we just use the frame ID in that case and simplify drop the undefined case in all this logic, or does that further complicate things?

@AleksanderBodurri AleksanderBodurri Jan 25, 2024

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not sure I'm following exactly but I replaced this with a more natural feeling frameHasUniqueUrl(frame: Frame | null): boolean that handles the null case by returning true

@dgp1130 dgp1130 Jan 26, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I meant something like:

export class FrameManager {
  getSelectedFrame(): Frame | null {
    if (this._selectedFrameId === null) {
      return null;
    }

    const frame = this._frames.get(this._selectedFrameId);
    if (!frame) return null;

    if (!this.frameHasUniqueUrl(frame)) {
      this._messageBus.emit('log', [ /* ... */ ]);
      return null;
    }

    return frame;
  }
}

This way getSelectedFrame automatically checks if the frame is unique so each usage doesn't need to do that.

I'm not sure if we ever need to distinguish between the _selectedFrameId === null case and the !this.frameAsUniqueUrl(frame) case, so hopefully return null; works in both of them without creating ambiguity. Otherwise we might need a discriminated union to disambiguate them.

Comment thread devtools/projects/shell-browser/src/manifest/manifest.chrome.json Outdated
Comment thread devtools/projects/ng-devtools/src/lib/frame_manager.ts Outdated
Comment thread devtools/projects/ng-devtools/src/lib/frame_manager.ts Outdated
Comment thread devtools/projects/ng-devtools/src/lib/frame_manager.ts Outdated
Comment thread devtools/projects/ng-devtools/src/lib/frame_manager.ts Outdated
@AleksanderBodurri
AleksanderBodurri force-pushed the devtools-iframe-support branch 10 times, most recently from 29c6ff9 to 5297a91 Compare January 26, 2024 04:00
@dgp1130
dgp1130 force-pushed the devtools-iframe-support branch from 24eb9ae to 06ffdc7 Compare February 15, 2024 00:52
@angular-robot angular-robot Bot removed the detected: feature PR contains a feature commit label Feb 15, 2024
@dgp1130 dgp1130 added action: merge The PR is ready for merge by the caretaker and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Feb 15, 2024
@AndrewKushnir

Copy link
Copy Markdown
Contributor

This PR was merged into the repository by commit ebcdc8d.

AndrewKushnir pushed a commit that referenced this pull request Feb 15, 2024
…3934)

In the Angular DevTools Chrome DevTools page:

- Angular DevTools is able to ask the background script to list each frame that has been registered on a page.
- Angular Devtools is able to ask the background script to "enable" the connection on a particular frame. This enables the messaging between the content script <-> background script <-> devtools page
- Implements detection of non unique urls on the inspected page

Limitations:
- The `inspectedWindow.eval` API is only able to target frames by frameURL. This means some features that integrate with Chrome DevTools like inspect element and open source will not be available when inspecting frames that do not have a unique url on the page.

PR Close #53934
AndrewKushnir pushed a commit that referenced this pull request Feb 15, 2024
…owser code (#53934)

Modifies the messaging layer of devtools to allow for switching communication between frames on a page. When served as a browser extension.

Design:
- When a page renders, DevTools installs a content script onto it through it's manifest file. The all_frames option is used here to install this script onto every frame in a page.
- When Angular is detected, the content script will install a backend script into it's frame.
- Each content script / backend script pairing is kept track of in the background script. This pairing represents an angular devtools context in a particular frame.
- Angular DevTools is able to ask the background script to list each frame that has been registered on a page.
- Angular Devtools is able to ask the background script to "enable" the connection on a particular frame. This enables the messaging between the content script <-> background script <-> devtools page

Limitations:
- The `inspectedWindow.eval` API is only able to target frames by frameURL. This means some features that integrate with Chrome DevTools like inspect element and open source will not be available when inspecting frames that do not have a unique url on the page.

PR Close #53934
AndrewKushnir pushed a commit that referenced this pull request Feb 15, 2024
…3934)

In the Angular DevTools Chrome DevTools page:

- Angular DevTools is able to ask the background script to list each frame that has been registered on a page.
- Angular Devtools is able to ask the background script to "enable" the connection on a particular frame. This enables the messaging between the content script <-> background script <-> devtools page
- Implements detection of non unique urls on the inspected page

Limitations:
- The `inspectedWindow.eval` API is only able to target frames by frameURL. This means some features that integrate with Chrome DevTools like inspect element and open source will not be available when inspecting frames that do not have a unique url on the page.

PR Close #53934
atscott pushed a commit to atscott/angular that referenced this pull request Feb 16, 2024
…owser code (angular#53934)

Modifies the messaging layer of devtools to allow for switching communication between frames on a page. When served as a browser extension.

Design:
- When a page renders, DevTools installs a content script onto it through it's manifest file. The all_frames option is used here to install this script onto every frame in a page.
- When Angular is detected, the content script will install a backend script into it's frame.
- Each content script / backend script pairing is kept track of in the background script. This pairing represents an angular devtools context in a particular frame.
- Angular DevTools is able to ask the background script to list each frame that has been registered on a page.
- Angular Devtools is able to ask the background script to "enable" the connection on a particular frame. This enables the messaging between the content script <-> background script <-> devtools page

Limitations:
- The `inspectedWindow.eval` API is only able to target frames by frameURL. This means some features that integrate with Chrome DevTools like inspect element and open source will not be available when inspecting frames that do not have a unique url on the page.

PR Close angular#53934
atscott pushed a commit to atscott/angular that referenced this pull request Feb 16, 2024
…gular#53934)

In the Angular DevTools Chrome DevTools page:

- Angular DevTools is able to ask the background script to list each frame that has been registered on a page.
- Angular Devtools is able to ask the background script to "enable" the connection on a particular frame. This enables the messaging between the content script <-> background script <-> devtools page
- Implements detection of non unique urls on the inspected page

Limitations:
- The `inspectedWindow.eval` API is only able to target frames by frameURL. This means some features that integrate with Chrome DevTools like inspect element and open source will not be available when inspecting frames that do not have a unique url on the page.

PR Close angular#53934
dgp1130 added a commit to dgp1130/angular that referenced this pull request Feb 27, 2024
dgp1130 added a commit to dgp1130/angular that referenced this pull request Feb 27, 2024
dylhunn pushed a commit that referenced this pull request Feb 27, 2024
dylhunn pushed a commit that referenced this pull request Feb 27, 2024
dylhunn pushed a commit that referenced this pull request Feb 27, 2024
dylhunn pushed a commit that referenced this pull request Feb 27, 2024
AleksanderBodurri added a commit to AleksanderBodurri/angular that referenced this pull request Mar 11, 2024
AleksanderBodurri added a commit to AleksanderBodurri/angular that referenced this pull request Mar 11, 2024
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Mar 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: devtools target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants