GithubHelp home page GithubHelp logo

Comments (8)

lvsti avatar lvsti commented on June 13, 2024

You should implement CEFRenderProcessHandler in the helper app.

from cef.swift.

WarWithinMe avatar WarWithinMe commented on June 13, 2024

@lvsti Should I also call CEFProcessUtils.initializeMain in the helper app? Not sure how to tell CEF that I would provide the CEFRednerProcessHandler

from cef.swift.

lvsti avatar lvsti commented on June 13, 2024

right, the demo app's helper is just a dummy... I might add a more useful helper app in the future, until then take a look at this example:

class App: CEFApp, CEFRenderProcessHandler {
    var renderProcessHandler: CEFRenderProcessHandler? {
        return self
    }

    func onContextCreated(browser: CEFBrowser, frame: CEFFrame, context: CEFV8Context) {
        context.enter()
        let v8Str = CEFV8Value.createString("Hello World!")
        NSLog("\(v8Str?.stringValue)")

        context.exit()
    }
}

let mainArgs = CEFMainArgs(arguments: CommandLine.arguments)
let commandLine = CEFCommandLine()!
commandLine.initFromArguments(CommandLine.arguments)

let retval: Int
if commandLine.switchValue(for: "type") == "renderer" {
    retval = CEFProcessUtils.executeProcess(with: mainArgs, app: App())
}
else {
    retval = CEFProcessUtils.executeProcess(with: mainArgs)
}

exit(Int32(retval))

from cef.swift.

lvsti avatar lvsti commented on June 13, 2024

Pro tip: debugging the helper app is not trivial since it runs in a separate process. In order to attach Xcode to the running render process, place the following line somewhere in the helper:

raise(SIGSTOP)

This will make the process hang and wait at that point until the debugger is attached. After that, you can use breakpoints as usual.

from cef.swift.

WarWithinMe avatar WarWithinMe commented on June 13, 2024

Thank you for the information

from cef.swift.

WarWithinMe avatar WarWithinMe commented on June 13, 2024

To use multi-process mode, if I want to implement logics (for example, js bindings) in main process, then I will need to use IPC to communicate with the render process. Or maybe I just move all the logics to render process, and only leave window management logics in the main process?

It seems that it will take a lot of effort to use multi-process mode.

from cef.swift.

lvsti avatar lvsti commented on June 13, 2024

It is indeed a lot of effort but so far neither I have found another way. Moving the logic over to the render process probably won't solve all your problems because that process is sandboxed, meaning it cannot access the filesystem, network etc.

from cef.swift.

WarWithinMe avatar WarWithinMe commented on June 13, 2024

Checked CefSharp, it sends message from the RenderProcess to MainProcess, to allow handling JS binding on the MainProcess. I'll try porting CefSharp's Subprocess logics to CEF.swift when I have time.

from cef.swift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.