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
Conversation
…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', () => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
extensions/amp-google-assistant-assistjs/0.1/assistjs-frame-service.js
Outdated
Show resolved
Hide resolved
extensions/amp-google-assistant-assistjs/0.1/assistjs-frame-service.js
Outdated
Show resolved
Hide resolved
…rvice.js Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
…rvice.js Co-authored-by: Justin Ridgewell <justin@ridgewell.name>
Seems like I don't have the permission to merge even all checks are passed. @samouri @jridgewell could you help me merge this? Thanks! |
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