正如你已经在标题中看到的,我的问题与popup.html有关
我不知道是什么问题请帮帮我!
这是错误代码
未检查运行时。lastError:无法建立连接。接收端不存在。堆栈跟踪弹出窗口。html:0(匿名功能)
popup.html为:
<!DOCTYPE html>
<html>
<head>
<style>
#popup-container {
width: 600px;
height: 800px;
}
</style>
<title>DissBott</title>
</head>
<body>
<h1>ChatGPT Extension</h1>
<p>input</p>
<textarea id="input"></textarea>
<br>
<button id="submitButton">Submit</button>
<button id="clearButton">Clear</button>
<br>
<p>Response:</p>
<p id="response"></p>
<script src="popup.js"></script>
</body>
</html>
js为:
// Popup Script
//background.js
const submitButton = document.getElementById("submitButton");
const clearButton = document.getElementById("clearButton");
const promptTextarea = document.getElementById("prompt");
const responseParagraph = document.getElementById("response");
submitButton.addEventListener("click", function() {
// onClick's logic below:
// Get the prompt from the textarea
const prompt = input;
// Send the message to the background script
chrome.runtime.sendMessage({
message: "clicked_browser_action",
prompt: prompt
}, function(response) {
// Display the response
responseParagraph.innerText = response;
});
});
clearButton.addEventListener("click", function() {
// Clear the textarea
promptTextarea.value = "";
// Clear the response
responseParagraph.innerText = "";
});
我的清单. json
{
"manifest_version": 3,
"name": "DissBot",
"description": "This is an extension that uses the ChatGPT model.",
"version": "1.0",
"host_permissions": [
"https://api.openai.com/"
],
"action": {
"default_popup": "popup.html"
},
"background": {
"script": ["bg.js"]
}
}
我试着做一个Chrome扩展,但没有成功。
1条答案
按热度按时间wfauudbj1#
下面是
chrome.runtime.sendMessage
的一个示例。manifest.json
popup.html
popup.js
background.js