diff --git a/lib/extension.js b/lib/extension.js index 7d8a6e2..c61c166 100644 --- a/lib/extension.js +++ b/lib/extension.js @@ -136,6 +136,16 @@ } }; + scope.createProxyFunction = function createProxyFunction(window, original, replacement){ + const wrappedWindow = scope.getWrapped(window); + const handler = wrappedWindow.Object.create(wrappedWindow.Object); + handler.apply = scope.exportFunctionWithName(function(target, thisArgs, args){ + // console.log(target, thisArgs, args); + return replacement.apply(thisArgs, args); + }, window, ""); + return new wrappedWindow.Proxy(original, handler); + }; + const changedPropertiesByWindow = new WeakMap(); scope.changeProperty = function(window, group, {object, name, type, changed}){ let changedProperties = changedPropertiesByWindow.get(scope.getWrapped(window)); diff --git a/lib/iframeProtection.js b/lib/iframeProtection.js index 42cf545..38461ab 100644 --- a/lib/iframeProtection.js +++ b/lib/iframeProtection.js @@ -25,7 +25,8 @@ const descriptor = Object.getOwnPropertyDescriptor(object, name); const original = descriptor[type]; if ((typeof changed) === "function"){ - changed = extension.exportFunctionWithName(changed, window, original.name); + // changed = extension.exportFunctionWithName(changed, window, original.name); + changed = extension.createProxyFunction(window, original, changed); } extension.changeProperty(window, "iframeProtection", {object, name, type, changed}); } diff --git a/lib/intercept.js b/lib/intercept.js index 8db72bc..ed77f03 100644 --- a/lib/intercept.js +++ b/lib/intercept.js @@ -240,7 +240,7 @@ name, changedFunction, siteStatus, original, window: windowToProcess, prefs, notify, checkStack, ask }){ - return function checker(callingDepth = 2){ + return function checker(callingDepth = 3){ const errorStack = (new Error()).stack; try { @@ -344,24 +344,39 @@ let changed; if (type ==="value"){ if (changedFunction.fakeGenerator){ - changed = extension.exportFunctionWithName( - changedFunction.fakeGenerator(checker, original, windowToProcess), - windowToProcess, - original.name - ); + // const proxy = new windowToProcess.Proxy(original, {apply: function(target, thisArgs, args){ + // console.log(target, thisArgs, args, generated); + // return generated.apply(thisArgs, args); + // }}); + if ((changedFunction.exportOptions || {}).allowCallbacks){ + changed = extension.exportFunctionWithName( + changedFunction.fakeGenerator(checker, original, windowToProcess), + windowToProcess, + original.name + ); + } + else { + const generated = changedFunction.fakeGenerator(checker, original, windowToProcess); + changed = extension.createProxyFunction(windowToProcess, original, generated); + } } else { changed = null; } } else { - changed = extension.exportFunctionWithName(function(){ - return extension.exportFunctionWithName( - changedFunction.fakeGenerator(checker), - windowToProcess, - original.name - ); - }, windowToProcess, descriptor.get.name); + // changed = extension.exportFunctionWithName(function(){ + // return extension.exportFunctionWithName( + // changedFunction.fakeGenerator(checker), + // windowToProcess, + // original.name + // ); + // }, windowToProcess, descriptor.get.name); + changed = extension.createProxyFunction(windowToProcess, original, extension.exportFunctionWithName( + changedFunction.fakeGenerator(checker), + windowToProcess, + original.name + )); } extension.changeProperty(windowToProcess, changedFunction.api, { object, name, type, changed @@ -393,7 +408,8 @@ extension.changeProperty(windowToProcess, changedGetter.api, { object, name, type: "get", - changed: extension.exportFunctionWithName(getter, windowToProcess, original.name) + // changed: extension.exportFunctionWithName(getter, windowToProcess, original.name) + changed: extension.createProxyFunction(windowToProcess, original, getter) } ); @@ -407,7 +423,8 @@ extension.changeProperty(windowToProcess, changedGetter.api, { object, name, type: "set", - changed: extension.exportFunctionWithName(setter, windowToProcess, original.name) + // changed: extension.exportFunctionWithName(setter, windowToProcess, original.name) + changed: extension.createProxyFunction(windowToProcess, original, setter) } ); } diff --git a/lib/modifiedCanvasAPI.js b/lib/modifiedCanvasAPI.js index 4935345..42797af 100644 --- a/lib/modifiedCanvasAPI.js +++ b/lib/modifiedCanvasAPI.js @@ -372,7 +372,8 @@ return function mozGetAsFile(callback){ return checkerWrapper(checker, this, arguments, useFakeCanvasCallback); }; - } + }, + exportOptions: {allowCallbacks: true} }, getImageData: { type: "readout",