-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
65 lines (57 loc) · 1.95 KB
/
popup.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
document.addEventListener('DOMContentLoaded', function() {
const scanButton = document.getElementById('scanButton');
const urlInput = document.getElementById('urlInput');
scanButton.addEventListener('click', function() {
const url = urlInput.value.trim();
if (url !== '') {
// Implement scan logic here
console.log('Scanning URL:', url);
// Add code to interact with Fortify WebInspect API using fetch or XMLHttpRequest
// Remember to handle the API request and response
} else {
console.log('Please enter a valid URL');
}
});
});
// Listen for clicks on the extension icon
chrome.action.onClicked.addListener((tab) => {
// Retrieve the active tab URL
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
const url = tabs[0]?.url;
if (url) {
initiateScan(url);
} else {
console.error('Unable to get active tab URL');
}
});
});
function initiateScan(url) {
const apiKey = 'YOUR_API_KEY'; // Replace with your actual API key
const apiUrl = 'https://api.example.com/webinspect/scans'; // Replace with the actual API endpoint
const body = {
url: url,
// Add other required parameters for the scan
};
fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`
// Add other necessary headers
},
body: JSON.stringify(body)
})
.then(response => {
if (response.ok) {
console.log('Scan initiated successfully');
// Handle success - maybe display a success message to the user
} else {
console.error('Failed to initiate scan');
// Handle error - display an error message to the user
}
})
.catch(error => {
console.error('Error initiating scan:', error);
// Handle any other errors that occur during the request
});
}