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

Webview: Background not applied? #5038

Closed
bpasero opened this issue Apr 6, 2016 · 14 comments
Closed

Webview: Background not applied? #5038

bpasero opened this issue Apr 6, 2016 · 14 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug upstream Issue identified as 'upstream' component related (exists outside of VS Code) verified Verification succeeded

Comments

@bpasero
Copy link
Member

bpasero commented Apr 6, 2016

image

I have a simple document provider just returning "Hello World" and it looks like the background of the web view is not fully applied?

@bpasero bpasero added the bug Issue identified by VS Code Team member as probable bug label Apr 6, 2016
@jrieken
Copy link
Member

jrieken commented Apr 6, 2016

I don't see that @bpasero Can you inspect how large the web view is drawn? And also how large the iframe is?

@jrieken jrieken added this to the April 2016 milestone Apr 6, 2016
@bpasero
Copy link
Member Author

bpasero commented Apr 6, 2016

@jrieken I verified that the webview itself is as large as the editor, so it must be the content within. Can you share with me how to show dev tools for the web view?

@bpasero
Copy link
Member Author

bpasero commented Apr 6, 2016

My extension btw:

/*---------------------------------------------------------
 * Copyright (C) Microsoft Corporation. All rights reserved.
 *--------------------------------------------------------*/
'use strict';

import * as vscode from 'vscode';

export function activate(context: vscode.ExtensionContext) {

    let previewUri = vscode.Uri.parse('css-preview://authority/css-preview');

    class TextDocumentContentProvider implements vscode.TextDocumentContentProvider {
        private _onDidChange = new vscode.EventEmitter<vscode.Uri>();

        public provideTextDocumentContent(uri: vscode.Uri): string {
            // return `<html>
            //     <body>
            //         <div>Preview of the CSS properties</dev>
            //         <hr>
            //         <div id="el">Lorem ipsum dolor sit amet, mi et mauris nec ac luctus lorem, proin leo nulla integer metus vestibulum lobortis, eget</div>
            //     </body>
            //     </html>`;
            return "hello world"
        }

        get onDidChange(): vscode.Event<vscode.Uri> {
            return this._onDidChange.event;
        }

        public update(uri: vscode.Uri) {
            this._onDidChange.fire(uri);
        }
    }

    let provider = new TextDocumentContentProvider();
    let registration = vscode.workspace.registerTextDocumentContentProvider('css-preview', provider);

    vscode.workspace.onDidChangeTextDocument((e: vscode.TextDocumentChangeEvent) => {
        if (e.document === vscode.window.activeTextEditor.document) {
            provider.update(previewUri);
        }
    });

    vscode.window.onDidChangeTextEditorSelection((e: vscode.TextEditorSelectionChangeEvent) => {
        if (e.textEditor === vscode.window.activeTextEditor) {
            provider.update(previewUri);
        }
    })

    let disposable = vscode.commands.registerCommand('extension.showCssPropertyPreview', () => {
        return vscode.commands.executeCommand('vscode.previewHtml', previewUri, vscode.ViewColumn.Two).then((success) => {
        }, (reason) => {
            vscode.window.showErrorMessage(reason);
        });

    });
    context.subscriptions.push(disposable, registration);
}

export function deactivate() {
}

@jrieken
Copy link
Member

jrieken commented Apr 6, 2016

There is something to uncomment in ManagedWebview in htmlPreviewPart.ts

@bpasero
Copy link
Member Author

bpasero commented Apr 7, 2016

Weird, now I don't see it at home. Will check tomorrow at work...

@jrieken
Copy link
Member

jrieken commented Apr 7, 2016

funky. I see it a little when resizing because the webview-body isn't styled, only the iframe. Maybe a resize event got lost - didn't make it to the iframe...

@bpasero
Copy link
Member Author

bpasero commented Apr 7, 2016

There is another issue where the background color of a webview is always white. I think this got fixed in newer versions of Electron though and might help us: https://github.com/electron/electron/releases/tag/v0.37.3

@bpasero
Copy link
Member Author

bpasero commented Apr 8, 2016

This seems to be related to the fact that I am running with "window.zoomLevel": 1. Also, once I resize the shell, the white background is filled. Maybe the zoom setting also needs to be applied explicitly to the webview.

@jrieken jrieken added the upstream Issue identified as 'upstream' component related (exists outside of VS Code) label Apr 14, 2016
@jrieken
Copy link
Member

jrieken commented Apr 14, 2016

This is better with the latest Electron update but initially, when loading the web view I still see a short flicker of white background, no matter if I statically set the background color to transparent or black etc

@bpasero
Copy link
Member Author

bpasero commented Apr 14, 2016

@jrieken ok, maybe follow up with Electron if you think webview should not have this flicker, I know that for the window itself they did quite some work for me to set the background color very early, even before the DOM gets any chance to set it.

@jrieken
Copy link
Member

jrieken commented Apr 15, 2016

electron/electron#5175

@jrieken
Copy link
Member

jrieken commented Apr 15, 2016

I might be able to workaround this by playing with visibility styles...

@jrieken jrieken removed this from the April 2016 milestone Apr 20, 2016
@kieferrm
Copy link
Member

This is also an issue for #6106.

@jrieken
Copy link
Member

jrieken commented Jul 5, 2016

Closing since we managed to workaround this using an opacity trick

@jrieken jrieken closed this as completed Jul 5, 2016
@bpasero bpasero added the verified Verification succeeded label Sep 1, 2016
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug upstream Issue identified as 'upstream' component related (exists outside of VS Code) verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

3 participants