Skip to content

Commit

Permalink
Add screen size and window position
Browse files Browse the repository at this point in the history
  • Loading branch information
bkrumnow authored and vringar committed Apr 26, 2023
1 parent 5711456 commit c9ec210
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 9 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,22 @@ OpenWPM<sub>hide</sub> introduces two new parameters to the BrowserParams object
Using both parameters works as follows:

```javascript
NUM_BROWSERS = 2
browser_params = [BrowserParams(display_mode="native") for _ in range(NUM_BROWSERS)]
for browser_param in browser_params:
browser_param.resolution = (1520, 630)
browser_param.position = (50, 100)
from hide_commands import (SetResolution, SetPosition)
...
command_sequence = CommandSequence(...)

command_sequence.append_command(SetResolution(width=1600, height=800), timeout=10)
command_sequence.append_command(SetPosition(x=50, y=200), timeout=10)
```

### Hardened JavaScript instrument
Set _stealth_js_instrument_ to _True_ to activate the hardened version (similar as above):

```javascript
NUM_BROWSERS = 2
browser_params = [BrowserParams(display_mode="native") for _ in range(NUM_BROWSERS)]
for browser_param in browser_params:
browser_param.stealth_js_instrument = True
NUM_BROWSERS = 2
browser_params = [BrowserParams(display_mode="native") for _ in range(NUM_BROWSERS)]
for browser_param in browser_params:
browser_param.stealth_js_instrument = True
```

Use the [settings.js](https://github.com/bkrumnow/OpenWPM/blob/stealth_extension/Extension/firefox/stealth.js/settings.js) file to
Expand Down
1 change: 1 addition & 0 deletions hide_commands/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .commands import (SetResolution, SetPosition)
73 changes: 73 additions & 0 deletions hide_commands/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
""" This file aims to demonstrate how to write custom commands in OpenWPM
Steps to have a custom command run as part of a CommandSequence
1. Create a class that derives from BaseCommand
2. Implement the execute method
3. Append it to the CommandSequence
4. Execute the CommandSequence
"""
import logging

from tkinter import ttk

from openwpm.commands.types import BaseCommand
from openwpm.config import BrowserParams, ManagerParams
from openwpm.socket_interface import ClientSocket

from selenium.webdriver import Firefox


def get_screen_resolution(driver):
return driver.execute_script("return [screen.width, screen.height];")


class SetResolution(BaseCommand):
""" Sets the browser window resolution """
def __init__(self, width, height) -> None:
self.logger = logging.getLogger("openwpm")
self.width = width
self.height = height

def __repr__(self) -> str:
return "SetResolution"

def execute(
self,
driver: Firefox,
browser_params: BrowserParams,
manager_params: ManagerParams,
extension_socket: ClientSocket,
):

self.logger.info(f"Setting window resolution to {self.width} x {self.height} ")
driver.set_window_size(self.width, self.height)

resolution = get_screen_resolution(driver)
if resolution[0] <= self.width or resolution[1] <= self.height:
self.logger.warn(
f"Browser window resolution ({self.width} x {self.height}) exceeds " +
f"screen resolution ({resolution[0]} x {resolution[1]})")



class SetPosition(BaseCommand):
""" Sets the browser window position """
def __init__(self, x, y) -> None:
self.logger = logging.getLogger("openwpm")
self.x = x
self.y = y

def __repr__(self) -> str:
return "SetPosition"

def execute(
self,
driver: Firefox,
browser_params: BrowserParams,
manager_params: ManagerParams,
extension_socket: ClientSocket,
):

driver.set_window_position(self.x, self.y, windowHandle='current')

0 comments on commit c9ec210

Please sign in to comment.