PyObjC BrowserEngineKit Bindings

12.1 · active · verified Tue Apr 14

PyObjC provides Python bindings for the BrowserEngineKit framework on macOS, allowing Python applications to embed web content rendering capabilities. It is part of the larger PyObjC project, which wraps many macOS frameworks. Version 12.1 is current, with releases typically aligning with macOS SDK updates and Python version support changes.

Warnings

Install

Imports

Quickstart

This example demonstrates how to instantiate a `BEBrowserViewController` within a minimal macOS GUI application using PyObjC. It creates a simple window and embeds the browser view controller's view into it. Running this code requires a macOS environment and will display an empty browser window.

import objc
from AppKit import NSApplication, NSWindow, NSMakeRect
from BrowserEngineKit import BEBrowserViewController
from PyObjCTools import AppHelper # Common for PyObjC GUI apps

class MyBrowserViewController(BEBrowserViewController):
    # A minimal subclass just to demonstrate extending BEBrowserViewController
    pass

class AppDelegate(objc.NSObject):
    def applicationDidFinishLaunching_(self, notification):
        self.mainWindow = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(
            NSMakeRect(100, 100, 800, 600),
            4 | 8 | 1 | 2, # Titled, Closable, Miniaturizable, Resizable
            2, # NSBackingStoreBuffered
            False
        )
        self.mainWindow.setTitle_("PyObjC BrowserEngineKit Demo")

        self.browserVC = MyBrowserViewController.alloc().init()
        self.mainWindow.setContentView_(self.browserVC.view())
        self.mainWindow.makeKeyAndOrderFront_(None)

def main():
    app = NSApplication.sharedApplication()
    delegate = AppDelegate.alloc().init()
    app.setDelegate_(delegate)
    AppHelper.runEventLoop() # Starts the macOS event loop

if __name__ == "__main__":
    main()

view raw JSON →