我正在尝试构建一个简单的 safari 应用扩展。在about:blank我从扩展的资源文件夹加载一个 html 页面。以下是代码。
//script.js - injected script
if(window.location.href=="about:blank"){
window.location.href = safari.extension.baseURI + "page.html";
}
Run Code Online (Sandbox Code Playgroud)
我想要这个加载的页面和 safari 应用程序之间的通信。显然注入的脚本script.js在加载的 html 页面上不可用。
我尝试将 链接script.js到 html 页面内联,但safari对象本身不可用于safari.extension.dispatchMessage或safari.self.addEventListener。
编辑:
有了这个(注入的脚本 script.js 在加载的 html 页面/选项卡上不可用,页面被加载)我的意思是在资源选项卡中打开 web 检查器时,我们看不到任何extension scripts
考虑到我们有some_function ,它打印结果stdout而不是返回它。改变它的定义超出了我们的范围,没有其他选择。我们可以选择从stdout. 所以问题。
如何读取 C++ 程序本身的标准输出。
pid如果我们可以获得fd相同的程序,则可以搜索我,但我找不到任何东西。
#include <unistd.h>
#include <sys/types.h>
#include <iostream>
void some_function(){
std::cout<<"Hello World";
}
int main(){
int pid = ::getpid();
string s = //What to write here.
cout<<"Printing";
some_function(); //This function prints "Hello World" to screen
cout<<s; //"PrintingHello World"
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如何将管道附加到同一个进程,而不是创建子进程。
有些人可能会想到创建子进程并调用some_function它,以便能够stdout在父进程中读取它,但是不,some_function取决于调用它的进程,因此我们希望将其称为进程而不是创建子进程。