Browse Source

Improve injector by lazy reading

Gerald 10 years ago
parent
commit
209c6215a4
1 changed files with 8 additions and 2 deletions
  1. 8 2
      src/injected.js

+ 8 - 2
src/injected.js

@@ -141,12 +141,18 @@ function getWrapper() {
   });
   // Wrap properties
   comm.forEach(comm.props, function (name) {
-    if (typeof window[name] === 'function') return;
+    if (wrapper[name]) return;
+    var modified = false;
+    var value;
     Object.defineProperty(wrapper, name, {
       get: function () {
-        var value = window[name];
+        if (!modified) value = window[name];
         return value === window ? wrapper : value;
       },
+      set: function (val) {
+        modified = true;
+        value = val;
+      },
     });
   });
   return wrapper;