forked from voho0000/GPT-testCase-chromeExtension
/
content.js
27 lines (25 loc) · 969 Bytes
/
content.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'getSelectedText') {
const selectedText = window.getSelection().toString();
fetch('http://127.0.0.1:5000/generate_test_case', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ defect_description: selectedText }),
})
.then((response) => response.json())
.then((data) => {
// Store the received test case in the local storage
chrome.storage.local.set({ testCase: data.test_steps });
// Send a message back to the background script to show the test case in the popup
chrome.runtime.sendMessage({
action: 'showTestCase',
testCase: data.test_steps,
});
})
.catch((error) => {
console.error('Error fetching test case:', error);
});
}
});