Skip to content

Webview: Background not applied? #5038

Closed

Description

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?

Activity

  1. added
    bug
    on Apr 6, 2016
  2. jrieken commented on Apr 6, 2016

    @jrieken
    Contributor

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

  3. bpasero commented on Apr 6, 2016

    @bpasero
    ContributorAuthor

    Johannes Rieken (@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?

  4. bpasero commented on Apr 6, 2016

    @bpasero
    ContributorAuthor

    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() {
    }
  5. jrieken commented on Apr 6, 2016

    @jrieken
    Contributor

    There is something to uncomment in ManagedWebview in htmlPreviewPart.ts

  6. bpasero commented on Apr 7, 2016

    @bpasero
    ContributorAuthor

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

  7. jrieken commented on Apr 7, 2016

    @jrieken
    Contributor

    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...

  8. bpasero commented on Apr 7, 2016

    @bpasero
    ContributorAuthor

    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

  9. bpasero commented on Apr 8, 2016

    @bpasero
    ContributorAuthor

    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.

  10. added
    upstream
    on Apr 14, 2016
  11. jrieken commented on Apr 14, 2016

    @jrieken
    Contributor

    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

  12. bpasero commented on Apr 14, 2016

    @bpasero
    ContributorAuthor

    Johannes Rieken (@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.

  13. jrieken commented on Apr 15, 2016

    @jrieken
    Contributor
  14. jrieken commented on Apr 15, 2016

    @jrieken
    Contributor

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

  15. kieferrm commented on May 31, 2016

    @kieferrm
    Member

    This is also an issue for #6106.

  16. jrieken commented on Jul 5, 2016

    @jrieken
    Contributor

    Closing since we managed to workaround this using an opacity trick

  17. locked and limited conversation to collaborators on Nov 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugupstreamverified

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions