c++ - Firebreath 插件 : How to get document properties in the c++ part?

标签 c++ dom firebreath

如何在c++部分获取文档属性?例如,我想获取 document.title 并将其存储在 firebreath 插件的 c++ 部分?

if (window && window->getJSObject()->HasProperty("domain")) {
    FB::JSObjectPtr docObj = window->getProperty<FB::JSObjectPtr>("document");

    consoleObj->Invoke("log", FB::variant_list_of("Has obtained document"));

    if(docObj && docObj->HasProperty("domain")){
        m_domain = docObj->getJSObject()->getProperty<std::string>("domain");
        consoleObj->Invoke("log", FB::variant_list_of("Has obtained domain: " + m_domain));
    }

}

但是这个编译失败,因为 docObj 没有方法 HasProperty。我不知道要使用什么辅助方法。

最佳答案

抱歉,当你在 FireBreath 聊天室提问时我正在 sleep 。一个稍微更简短的方法是:

FB::DOM::DocumentPtr dom = m_host->getDOMDocument();
try {
    if (dom && dom->getJSObject()->HasProperty("title")) {
        std::string title = m_host->getDOMDocument()->getProperty<std::string>("title");
    }
} catch (...) {
    // Could not get the title
}

您应该始终将 convert_cast 包装在 try .. catch 中,以防转换失败。此处 DOM::Document 对象的 getProperty 抽象基本上只是在内部执行 convert_cast。

关于c++ - Firebreath 插件 : How to get document properties in the c++ part?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19289860/

相关文章:

javascript - clientWidth "lying",无法确定元素的实际宽度

c++ - 如何在 C++ 中将 const FB::variant& 转换为用户定义的类?

javascript - 如何捕获页面上的所有滚动事件,而不将 onscroll 处理程序附加到每个容器

php - 用 PHP 用 div 包装 HTML 片段(并从 HTML 标签生成目录)

c++ - Visual Studio 2013,错误 MSB8020 : The build tools for Visual Studio 2010 cannot be found

c++ - 运行具有授予权限的 NPAPI 插件 (firebreath)

c++ - 如何将 const void* 转换为 unsigned int?

c++ - 为什么我的函数不能传递正确的值?

c++ - 为什么 srand(time(NULL)) 即使我反复重置它也能顺利工作?

c++ - LLVM/OpenMP 中的互斥量非常慢