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

✨ Assist.js: Add a shared FrameService to assistjs extension #32784

Merged
merged 35 commits into from Feb 25, 2021

Conversation

ychsieh
Copy link
Contributor

@ychsieh ychsieh commented Feb 22, 2021

The new service enables all custom elements to handle requests from underlying iframes by talking to the Assistant iframe. The implementation of two endpoints(OpenMic and SendTextQuery) is empty now and would be implemented in the upcoming PRs(after the message channel between main document and iframes are constructed).

Assist.js AMP integration I2I issue: #30631

@samouri
/cc @ianba

ychsieh and others added 28 commits January 26, 2021 08:12
…sistant-assistjs. It consists of one shared service and multiple custom elements.
runtime dependency in package.json
- Add appropriate validator rules for the new extension
- Add more detailed description about what this extension does
… Also includes some minor refactoring.

The service provides config to other components and the element take prespecified config json.
- Ensure config json retrieval
- Move widget iframe url creation into one single place.
- Add assertion to ensure there's only one config element on the page

Minor fixes:
- Replace await usage with then to avoid extra dependencies.
- Update validator rules for the invisible config element
…rvice.js

Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
…aseElement).

Also add a config service mock to the unit test.
- Parse config in config element to save a DOM query
- Delete assistjs-frame-service.js. Add it in next PR with real usage.
…from underlying iframes.

Actual implementation of two endpoints: OpenMic and SendTextQuery is empty now and will be implemented in upcoming PRs.

/** @private */
createAssistantIframe_() {
document.addEventListener('DOMContentLoaded', () => {
Copy link
Member

Choose a reason for hiding this comment

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

@jridgewell: is it important to use ampdoc.whenReady() ==> Promise instead of DOMContentLoaded?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to whenReady() because it seems like it is necessary. I double checked and realized that without it the iframe never gets created. I guess DOMContentLoaded might somehow got intercepted.

createAssistantIframe_() {
document.addEventListener('DOMContentLoaded', () => {
this.configService_ = Services.assistjsConfigServiceForDoc(this.ampDoc_);
const iframe = this.win.document.createElement('iframe');
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 add sandbox to the iframe? And only give permissions it needs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Add sandbox attributes to all iframes.
@ychsieh
Copy link
Contributor Author

ychsieh commented Feb 25, 2021

Seems like I don't have the permission to merge even all checks are passed. @samouri @jridgewell could you help me merge this? Thanks!

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

Successfully merging this pull request may close these issues.

None yet

4 participants