@@ -9,18 +9,18 @@ var weblocs = [/^https:\/\/glowscript\.org$/, // put a couple of these explicitl
9
9
/ ^ h t t p s : \/ \/ H O S T _ N A M E _ T E M P L A T E $ /
10
10
]
11
11
12
- function checkTrustedHosts ( aHost ) { // go through the known trusted hosts
13
- let found = false ;
14
- let trimhost = aHost . replace ( 'www.' , '' ) // remove www. if it's there
15
- //console.log("checking trusted hosts:" + aHost);
16
- for ( let i = 0 ; i < weblocs . length ; i ++ ) {
17
- found = trimhost . match ( weblocs [ i ] ) ;
18
- if ( found ) {
19
- break ;
20
- }
12
+ function checkTrustedHosts ( aHost ) {
13
+ // go through the known trusted hosts
14
+ let found = false
15
+ //console.log("checking trusted hosts as:", aHost)
16
+ for ( let i = 0 ; i < weblocs . length ; i ++ ) {
17
+ found = aHost . match ( weblocs [ i ] )
18
+ if ( found ) {
19
+ break
21
20
}
22
- //console.log("Found =" + found);
23
- return ! found ; // return true to bail out.
21
+ }
22
+ //console.log("Found =" + found)
23
+ return ! found // return true to bail out.
24
24
}
25
25
26
26
window . glowscript_libraries = { // used for unpackaged (X.Ydev) version
@@ -197,12 +197,22 @@ function ideRun() {
197
197
send ( { ready :true } )
198
198
function receiveMessage ( event ) {
199
199
event = event . originalEvent // originalEvent is a jquery entity
200
- trusted_origin = event . origin
200
+ let trimhost = event . origin . replace ( "sandbox." , "" ) // remove sandbox. if it's there
201
+ //trimhost = trimhost.replace("sandbox.", "") // remove www. if it's there
202
+ trusted_origin = trimhost
203
+ //console.log("in iFrame: receivedMessage from: " + event.origin)
201
204
//console.log("Setting trusted_origin:" + trusted_origin)
202
- if ( checkTrustedHosts ( trusted_origin ) ) { // ensure that message is from glowscript
203
- return ;
205
+ if ( checkTrustedHosts ( trusted_origin ) ) {
206
+ // ensure that message is from glowscript
207
+ //console.log("rejecting origin!")
208
+ return
209
+ }
210
+ try {
211
+ var message = JSON . parse ( event . data )
212
+ } catch ( err ) {
213
+ //console.log("in iFrame: receivedMessage: JSON parse error on " + event.data)
214
+ return
204
215
}
205
- var message = JSON . parse ( event . data )
206
216
if ( message . program !== undefined ) {
207
217
// Determine the set of libraries to load
208
218
var progver = message . version . substr ( 0 , 3 ) // 'unp' if unpackaged
@@ -312,6 +322,9 @@ function ideRun() {
312
322
313
323
function screenshot ( isAuto ) {
314
324
var scene
325
+ if ( ! canvas . activated ) {
326
+ return
327
+ }
315
328
for ( var c = 0 ; c < canvas . activated . length ; c ++ ) {
316
329
var ca = canvas . activated [ c ]
317
330
if ( ca !== null ) {
0 commit comments