提交 fbf201b2 编写于 作者: M Matt Bierner

Add conditional guards around access to body in webview pre

For #70790

Something is causing `x.body` to error out in some cases on windows for webviews. I can't repo the bug but am adding these guards based on the error stack
上级 d81145d3
......@@ -184,6 +184,9 @@ module.exports = function createWebviewManager(host) {
let isHandlingScroll = false;
const handleInnerScroll = (event) => {
if (!event.target || !event.target.body) {
return;
}
if (isHandlingScroll) {
return;
}
......@@ -205,6 +208,10 @@ module.exports = function createWebviewManager(host) {
};
document.addEventListener('DOMContentLoaded', () => {
if (!document.body) {
return;
}
host.onMessage('styles', (_event, variables, activeTheme) => {
initData.styles = variables;
initData.activeTheme = activeTheme;
......@@ -214,7 +221,9 @@ module.exports = function createWebviewManager(host) {
return;
}
applyStyles(target.contentDocument, target.contentDocument.body);
if (target.contentDocument) {
applyStyles(target.contentDocument, target.contentDocument.body);
}
});
// propagate focus
......@@ -346,15 +355,15 @@ module.exports = function createWebviewManager(host) {
return false;
};
let onLoad = (contentDocument, contentWindow) => {
if (contentDocument.body) {
const onLoad = (contentDocument, contentWindow) => {
if (contentDocument && contentDocument.body) {
// Workaround for https://github.com/Microsoft/vscode/issues/12865
// check new scrollY and reset if neccessary
setInitialScrollPosition(contentDocument.body, contentWindow);
}
const newFrame = getPendingFrame();
if (newFrame && newFrame.contentDocument === contentDocument) {
if (newFrame && newFrame.contentDocument && newFrame.contentDocument === contentDocument) {
const oldActiveFrame = getActiveFrame();
if (oldActiveFrame) {
document.body.removeChild(oldActiveFrame);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册