Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/core/main/client/net/connection.js
1154 views
1
//
2
// Copyright (c) 2006-2025 Wade Alcorn - [email protected]
3
// Browser Exploitation Framework (BeEF) - https://beefproject.com
4
// See the file 'doc/COPYING' for copying permission
5
//
6
7
/**
8
* beef.net.connection - wraps Mozilla's Network Information API
9
* https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation
10
* https://developer.mozilla.org/en-US/docs/Web/API/Navigator/connection
11
* @namespace beef.net.connection
12
*/
13
beef.net.connection = {
14
15
/**
16
* Returns the connection type. https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation/type
17
* @example beef.net.connection.type()
18
* @return {String} connection type or 'unknown'.
19
*/
20
type: function () {
21
try {
22
var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
23
var type = connection.type;
24
if (/^[a-z]+$/.test(type)) return type; else return 'unknown';
25
} catch(e) {
26
beef.debug("Error retrieving connection type: " + e.message);
27
return 'unknown';
28
}
29
},
30
31
/**
32
* Returns the maximum downlink speed of the connection. https://developer.mozilla.org/en-US/docs/Web/API/NetworkInformation/downlinkMax
33
* @example beef.net.connection.downlinkMax()
34
* @return {String} downlink max or 'unknown'.
35
*/
36
downlinkMax: function () {
37
try {
38
var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection;
39
var max = connection.downlinkMax;
40
if (max) return max; else return 'unknown';
41
} catch(e) {
42
beef.debug("Error retrieving connection downlink max: " + e.message);
43
return 'unknown';
44
}
45
}
46
47
};
48
49
beef.regCmp('beef.net.connection');
50
51
52