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

core: error msg for dynamic plugin in Colab #2388

Merged
merged 2 commits into from
Jun 27, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 53 additions & 21 deletions tensorboard/components/tf_tensorboard/tf-tensorboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,20 @@ <h3>There’s no dashboard by the name of “<tt>[[_selectedDashboard]]</tt>.”
}
}
</style>
<template id="colabNotSupported" preserve-content>
<div style="max-width: 540px; margin: 80px auto 0 auto;">
<h3>Dynamic plugin isn’t supported in Colab yet.</h3>
wchargin marked this conversation as resolved.
Show resolved Hide resolved
<p>
Please see
<a
href="https://github.com/tensorflow/tensorboard/issues/1913"
Copy link
Contributor

@wchargin wchargin Jun 26, 2019

Choose a reason for hiding this comment

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

Do you plan to broaden this issue from the profile plugin to “plugins
that use iframes” or similar? I’d be confused if I happened upon this
issue from the projector plugin.

(edit: I guess this is probably what you meant by the last line of the
PR description; SGTM.)

rel="noopener"
target="_blank"
>GitHub issue #1913</a>
for more information.
</p>
</div>
</template>
</template>
<script src="autoReloadBehavior.js"></script>
<script>
Expand Down Expand Up @@ -581,7 +595,12 @@ <h3>There’s no dashboard by the name of “<tt>[[_selectedDashboard]]</tt>.”
_refreshing: {
type: Boolean,
value: false,
}
},
_inColab: {
type: Boolean,
value: () => !!(window.TENSORBOARD_ENV || {}).IN_COLAB,
readOnly: true,
},
},
observers: [
('_updateSelectedDashboardFromActive(' +
Expand Down Expand Up @@ -757,26 +776,8 @@ <h3>There’s no dashboard by the name of “<tt>[[_selectedDashboard]]</tt>.”
break;
}
case 'IFRAME': {
const iframe = document.createElement('iframe');
iframe.id = 'dashboard'; // used in `_selectedDashboardComponent`
this.scopeSubtree(iframe);
container.appendChild(iframe);
const subdocument = iframe.contentDocument;
const pluginBasePath = tf_backend.getRouter()
.pluginRoute(selectedDashboard, '/')
const base = subdocument.createElement('base');
// TODO(stephanwlee): Use sanitized URL when setting the href.
// setAttribute is a bypass for the security conformance which we
// have no way to address.
base.setAttribute(
'href',
String(new URL(pluginBasePath, window.location.href)));
subdocument.head.appendChild(base);
const script = subdocument.createElement('script');
const moduleString = JSON.stringify(loadingMechanism.modulePath);
script.textContent =
`import(${moduleString}).then((m) => void m.render());`;
subdocument.body.appendChild(script);
this._renderPluginIframe(
container, selectedDashboard, loadingMechanism);
break;
}
default: {
Expand All @@ -788,6 +789,37 @@ <h3>There’s no dashboard by the name of “<tt>[[_selectedDashboard]]</tt>.”
this.set('_isReloadDisabled', dashboard.disableReload);
},

_renderPluginIframe(container, selectedDashboard, loadingMechanism) {
if (this._inColab) {
const templateContent = this.$.colabNotSupported.content;
const node = document.importNode(templateContent, true);
node.id = 'dashboard'; // used in `_selectedDashboardComponent`
this.scopeSubtree(node);
container.appendChild(node);
return;
stephanwlee marked this conversation as resolved.
Show resolved Hide resolved
}
const iframe = document.createElement('iframe');
iframe.id = 'dashboard'; // used in `_selectedDashboardComponent`
this.scopeSubtree(iframe);
container.appendChild(iframe);
const subdocument = iframe.contentDocument;
const pluginBasePath = tf_backend.getRouter()
.pluginRoute(selectedDashboard, '/')
const base = subdocument.createElement('base');
// TODO(stephanwlee): Use sanitized URL when setting the href.
// setAttribute is a bypass for the security conformance which we
// have no way to address.
base.setAttribute(
'href',
String(new URL(pluginBasePath, window.location.href)));
subdocument.head.appendChild(base);
const script = subdocument.createElement('script');
const moduleString = JSON.stringify(loadingMechanism.modulePath);
script.textContent =
`import(${moduleString}).then((m) => void m.render());`;
subdocument.body.appendChild(script);
},

/**
* Get the Polymer component corresponding to the currently
* selected dashboard. For instance, the result might be an
Expand Down