firefox-addon - 如何在扩展的本机应用程序中运行 firefox?
问题描述
我正在尝试简单地修改扩展示例以运行 firefox,但我收到一条消息提示:
Firefox is already running,but is no responding. To open a new new window, you must firest close the existing Firefox process, or restart your system.
#!/usr/bin/env python3
import sys
import json
import struct
import subprocess
try:
# Python 3.x version
# Read a message from stdin and decode it.
def getMessage():
rawLength = sys.stdin.buffer.read(4)
if len(rawLength) == 0:
sys.exit(0)
messageLength = struct.unpack('@I', rawLength)[0]
message = sys.stdin.buffer.read(messageLength).decode('utf-8')
return json.loads(message)
# Encode a message for transmission,
# given its content.
def encodeMessage(messageContent):
encodedContent = json.dumps(messageContent).encode('utf-8')
encodedLength = struct.pack('@I', len(encodedContent))
return {'length': encodedLength, 'content': encodedContent}
# Send an encoded message to stdout
def sendMessage(encodedMessage):
sys.stdout.buffer.write(encodedMessage['length'])
sys.stdout.buffer.write(encodedMessage['content'])
sys.stdout.buffer.flush()
while True:
receivedMessage = getMessage()
if receivedMessage == "ping":
run_result=subprocess.run('firefox -P firefox_word ',shell=True,stdout=subprocess.PIPE)
sendMessage(encodeMessage("pong3"))
except AttributeError:
pass
我的目的是通过我的扩展程序或我的扩展程序的本机应用程序打开一个本地 html 文件。
解决方案
对我来说,我需要在相同的配置文件中工作,现在我的解决方案是一个 shell 脚本作为守护进程来读取 fifo,并且我的扩展程序的本机应用程序在我需要运行 firefox 时写入该 fifo。请注意,您需要在扩展的本机应用程序之外运行该守护程序。
推荐阅读
- laravel - 如何在 Laravel 中使用 Getter Setter 方法?以及如何使用 Eloquent 模型添加字段?
- yii2 - 如何在表单中传递用户 ID
- angular - 在 onIdleStart 内部不调用 ajax
- c# - 如何在 ASP.NET Identity 中使用 OnModelCreating 添加管理员用户?
- c++ - 无法使用 OpenSSL 1.1.1 从 ClientHello 检索服务器名称 (SNI)
- hyperledger - 用于移动应用创建钱包和离线签名的 Hyperledger Fabric
- c# - Microsoft Teams 会议中的交互级别检查
- javascript - 从nodejs中的mongoDB查询返回数据
- angular - 数组的语法和格式
- java - SQLite 检查重复的用户名