@duckduckgo/content-scope-scripts
    Preparing search index...

    Class WebkitMessagingTransportImplements

    On macOS 11+, this will just call through to window.webkit.messageHandlers.x.postMessage

    Eg: for a foo message defined in Swift that accepted the payload {"bar": "baz"}, the following would occur:

    const json = await window.webkit.messageHandlers.foo.postMessage({ bar: "baz" });
    const response = JSON.parse(json)

    On macOS 10 however, the process is a little more involved. A method will be appended to navigator.duckduckgo that allows the response to be delivered there instead. It's not exactly this, but you can visualize the flow as being something along the lines of:

    // add the callback method to navigator.duckduckgo
    navigator.duckduckgo["_0123456"] = (response) => {
    // decrypt `response` and deliver the result to the caller here
    // then remove the temporary method
    delete navigator.duckduckgo['_0123456']
    };

    // send the data + `messageHanding` values
    window.webkit.messageHandlers.foo.postMessage({
    bar: "baz",
    messagingHandling: {
    methodName: "_0123456",
    secret: "super-secret",
    key: [1, 2, 45, 2],
    iv: [34, 4, 43],
    }
    });

    // later in swift, the following JavaScript snippet will be executed
    (() => {
    navigator.duckduckgo['_0123456']({
    ciphertext: [12, 13, 4],
    tag: [3, 5, 67, 56]
    })
    })()
    Index

    Constructors

    Properties

    capturedWebkitHandlers: Record<string, any> = {}
    config: any
    messagingContext: any

    Methods

    • When required (such as on macos 10.x), capture the postMessage method on each webkit messageHandler

      Parameters

      • handlerNames: string[]

      Returns void