Transparent background WKWebView (NSView)

I am building a Mac application using Swift. Therefor, I want to make a WKWebView transparent, so it shows the text of the loaded HTML, but the background of my underlaying NSWindow is visible.
I tried

webView.layer?.backgroundColor = NSColor.clearColor().CGColor;

which hadn’t any effect. WKWebView inherits from NSView, but I don’t know if this helps.

  • How Do I Access IBOutlets From Other Classes in Objective-C?
  • Using Swift with an OS X Preference Pane plugin
  • How can I link a dynamic library in Xcode?
  • Building a backwards compatible OS X app, when a new API is present?
  • OSX preferences file - removePersistentDomainForName has different functionality in 10.8?
  • How can I 'break away' from Cocoa and develop Mac OpenGL applications in C/C++?
  • Another solution would be to insert a NSVisualEffectView as the background of the WebView, but I don’t know how to accomplish that, either!

    3 Solutions Collect From Internet About “Transparent background WKWebView (NSView)”

    It was not supported, then they fixed it:

    https://bugs.webkit.org/show_bug.cgi?id=134779

    The way to make it transparent is to:

    myWebView.opaque = false
    

    Code below works for me perfectly, also color is set to clearColor by default.

    [wkWebView setValue:YES forKey:@"drawsTransparentBackground"];
    

    Use this in macOS 10.12 and higher:

    webView.setValue(false, forKey: "drawsBackground")