forked from auchenberg/firefox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
109 lines (92 loc) · 2.33 KB
/
test.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
var assert = require('assert'),
FirefoxClient = require("./index").default;
var url = "http://harthur.github.io/bugzilla-todos";
getFirstTab(function(tab) {
tab.DOM.querySelector("#title", function(err, node) {
console.log("got node:", node.tagName);
tab.DOM.getUsedFontFaces(node, { includePreviews: true }, function(err, fonts) {
for (var i in fonts) {
var font = fonts[i];
console.log("first font", font);
}
});
})
});
/*
loadUrl(url, function(tab) {
tab.DOM.querySelector("#title", function(err, node) {
console.log("got node:", node.tagName);
tab.DOM.getUsedFontFaces(node, function(err, fonts) {
for (var i in fonts) {
var font = fonts[i];
console.log("first font", font);
}
tab.StyleSheets.getStyleSheets(function(err, sheets) {
sheets[1].getMediaRules(function(err, rules) {
console.log("media rules: ", rules.length);
console.log("first one: ", rules[0]);
});
})
}) */
/**
{ fromFontGroup: true,
fromLanguagePrefs: false,
fromSystemFallback: false,
name: 'Georgia',
CSSFamilyName: 'Georgia',
rule: null,
srcIndex: -1,
URI: '',
localName: '',
format: '',
metadata: '' }
tab.DOM.querySelector("#title", function(err, node) {
console.log("got node:", node.tagName);
tab.DOM.getUsedFontFaces(node, function(err, fonts) {
for (var i in fonts) {
var font = fonts[i];
console.log("first font", font);
}
});
})
}) */
/**
{ fromFontGroup: true,
fromLanguagePrefs: false,
fromSystemFallback: false,
name: 'Georgia',
CSSFamilyName: 'Georgia',
rule: null,
srcIndex: -1,
URI: '',
localName: '',
format: '',
metadata: '' }
*/
/**
* Helper functions
*/
function loadUrl(url, callback) {
getFirstTab(function(tab) {
console.log("GOT TAB");
tab.navigateTo(url);
tab.once("navigate", function() {
console.log("NAVIGATED");
callback(tab);
});
});
}
function getFirstTab(callback) {
var client = new FirefoxClient({log: true});
client.connect(function() {
client.listTabs(function(err, tabs) {
if (err) throw err;
var tab = tabs[0];
// attach so we can receive load events
tab.attach(function(err) {
if (err) throw err;
callback(tab);
})
});
});
}