FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
three.js/devtools/background.js at dev · supermedium/three.js · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
supermedium
/
three.js
Public
forked from
mrdoob/three.js
Notifications
You must be signed in to change notification settings
Fork
36
Star
41
Code
Issues
1
Pull requests
1
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
three.js
/
devtools
/
background.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
185 lines (114 loc) · 3.86 KB
Breadcrumbs
three.js
/
devtools
/
background.js
Copy path
File metadata and controls
185 lines (114 loc) · 3.86 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/* global chrome */
importScripts
(
'constants.js'
)
;
// Map tab IDs to connections
const
connections
=
new
Map
(
)
;
// Handle extension icon clicks in the toolbar
chrome
.
action
.
onClicked
.
addListener
(
(
tab
)
=>
{
// Send scroll-to-canvas message to the content script (no UUID = scroll to first canvas)
chrome
.
tabs
.
sendMessage
(
tab
.
id
,
{
name
:
MESSAGE_SCROLL_TO_CANVAS
,
tabId
:
tab
.
id
}
)
.
catch
(
(
)
=>
{
// Ignore error - tab might not have the content script injected
console
.
log
(
'Could not send scroll-to-canvas message to tab'
,
tab
.
id
)
;
}
)
;
}
)
;
// Listen for connections from the devtools panel
chrome
.
runtime
.
onConnect
.
addListener
(
port
=>
{
let
tabId
;
// Messages that should be forwarded to content script
const
forwardableMessages
=
new
Set
(
[
MESSAGE_REQUEST_STATE
,
MESSAGE_REQUEST_OBJECT_DETAILS
,
MESSAGE_SCROLL_TO_CANVAS
,
MESSAGE_HIGHLIGHT_OBJECT
,
MESSAGE_UNHIGHLIGHT_OBJECT
]
)
;
// Listen for messages from the devtools panel
port
.
onMessage
.
addListener
(
message
=>
{
if
(
message
.
name
===
MESSAGE_INIT
)
{
tabId
=
message
.
tabId
;
connections
.
set
(
tabId
,
port
)
;
}
else
if
(
forwardableMessages
.
has
(
message
.
name
)
&&
tabId
)
{
chrome
.
tabs
.
sendMessage
(
tabId
,
message
)
;
}
else
if
(
tabId
===
undefined
)
{
console
.
warn
(
'Background: Message received from panel before init:'
,
message
)
;
}
}
)
;
// Clean up when devtools is closed
port
.
onDisconnect
.
addListener
(
(
)
=>
{
if
(
tabId
)
{
connections
.
delete
(
tabId
)
;
}
}
)
;
}
)
;
// Listen for messages from the content script
chrome
.
runtime
.
onMessage
.
addListener
(
(
message
,
sender
,
sendResponse
)
=>
{
if
(
message
.
scheme
)
{
chrome
.
action
.
setIcon
(
{
path
:
{
128
:
`icons/128-
${
message
.
scheme
}
.png`
}
}
)
;
}
if
(
sender
.
tab
)
{
const
tabId
=
sender
.
tab
.
id
;
// If three.js is detected, show a badge
if
(
message
.
name
===
MESSAGE_REGISTER
&&
message
.
detail
&&
message
.
detail
.
revision
)
{
const
revision
=
String
(
message
.
detail
.
revision
)
;
const
number
=
revision
.
replace
(
/
\D
+
$
/
,
''
)
;
const
isDev
=
revision
.
includes
(
'dev'
)
;
chrome
.
action
.
setBadgeText
(
{
tabId
:
tabId
,
text
:
number
}
)
.
catch
(
(
)
=>
{
// Ignore error - tab might have been closed
}
)
;
chrome
.
action
.
setBadgeTextColor
(
{
tabId
:
tabId
,
color
:
'#ffffff'
}
)
.
catch
(
(
)
=>
{
// Ignore error - tab might have been closed
}
)
;
chrome
.
action
.
setBadgeBackgroundColor
(
{
tabId
:
tabId
,
color
:
isDev
?
'#ff0098'
:
'#049ef4'
}
)
.
catch
(
(
)
=>
{
// Ignore error - tab might have been closed
}
)
;
}
const
port
=
connections
.
get
(
tabId
)
;
if
(
port
)
{
// Forward the message to the devtools panel
try
{
port
.
postMessage
(
message
)
;
// Send immediate response to avoid "message channel closed" error
sendResponse
(
{
received
:
true
}
)
;
}
catch
(
e
)
{
console
.
error
(
'Error posting message to devtools:'
,
e
)
;
// If the port is broken, clean up the connection
connections
.
delete
(
tabId
)
;
}
}
}
return
false
;
// Return false to indicate synchronous handling
}
)
;
// Listen for page navigation events
chrome
.
webNavigation
.
onCommitted
.
addListener
(
details
=>
{
const
{
tabId
,
frameId
}
=
details
;
// Clear badge on navigation, only for top-level navigation
if
(
frameId
===
0
)
{
chrome
.
action
.
setBadgeText
(
{
tabId
:
tabId
,
text
:
''
}
)
.
catch
(
(
)
=>
{
// Ignore error - tab might have been closed
}
)
;
}
const
port
=
connections
.
get
(
tabId
)
;
if
(
port
)
{
port
.
postMessage
(
{
id
:
MESSAGE_ID
,
name
:
MESSAGE_COMMITTED
,
frameId
:
frameId
}
)
;
}
}
)
;
// Clear badge when a tab is closed
chrome
.
tabs
.
onRemoved
.
addListener
(
(
tabId
)
=>
{
chrome
.
action
.
setBadgeText
(
{
tabId
:
tabId
,
text
:
''
}
)
.
catch
(
(
)
=>
{
// Ignore error - tab is already gone
}
)
;
// Clean up connection if it exists for the closed tab
if
(
connections
.
has
(
tabId
)
)
{
connections
.
delete
(
tabId
)
;
}
}
)
;
Back
|
FazBrowse Home
|
New Git URL