Open starkdm opened 1 year ago
How can I change the values of BatteryManager properties? The problem is that the navigator.getBattery() method is asynchronous and returns Promise. When using ReplaceWithProxy method I can't pass async handler.
navigator.getBattery()
ReplaceWithProxy
utils.replaceWithProxy(Object.getPrototypeOf(navigator), 'getBattery', { apply: (target, ctx, args) => { var promise = utils.cache.Reflect.apply(...arguments); /* const batteryMgr = await promise; utils.replaceProperty(batteryMgr, 'charging', { get: () => true }); utils.replaceProperty(batteryMgr, 'chargingTime', { get: () => 0 }); utils.replaceProperty(batteryMgr, 'dischargingTime', { get: () => Infinity }); utils.replaceProperty(batteryMgr, 'level', { get: () => 1 }); */ return promise; //Promise.resolve(batteryMgr); } });
The purpose is to hide battery info to avoid being tracked by websites.
How can I change the values of BatteryManager properties? The problem is that the
navigator.getBattery()
method is asynchronous and returns Promise. When usingReplaceWithProxy
method I can't pass async handler.The purpose is to hide battery info to avoid being tracked by websites.