Browse Source

Script injection, element picker, messaging

- Add script injection to vAPI, plus a raw implementation for Safari
  (element-picker.js requires it)
- Tweak element picker to work with Safari
- Revert a change from previous commit: element-picker.js' background
  message handler (since actually it can have its own messaging channel)
- Don't send "undefined" reponses from background to content
pull/2/head
Deathamns 10 years ago
committed by gorhill
parent
commit
34e1df3218
  1. 12
      src/js/vapi-client.js

12
src/js/vapi-client.js

@ -27,12 +27,12 @@ var messagingConnector = function(response) {
if (response.requestId) {
listener = vAPI.messaging.listeners[response.requestId];
}
if (!listener) {
channel = vAPI.messaging.channels[response.portName];
listener = channel && channel.listener;
}
}
if (typeof listener === 'function') {
delete vAPI.messaging.listeners[response.requestId];
@ -230,7 +230,6 @@ if (window.chrome) {
// relevant?
// https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/MessagesandProxies/MessagesandProxies.html#//apple_ref/doc/uid/TP40009977-CH14-SW12
vAPI.messaging = {
port: null,
requestId: 0,
listeners: {},
channels: {},
@ -240,10 +239,19 @@ if (window.chrome) {
vAPI.messaging.connector(msg.message);
};
safari.self.addEventListener('message', this._connector, false);
this.channels['vAPI'] = {
listener: function(msg) {
if (msg.cmd === 'runScript' && msg.details.code) {
Function(msg.details.code).call(window);
}
}
};
},
close: function() {
if (this._connector) {
safari.self.removeEventListener('message', this._connector, false);
this.channels = this.listeners = null;
}
},
channel: function(name, callback) {

Loading…
Cancel
Save