Browser Functionality

Currently, all Supported Browsers use the same generic class browser_history.generic.Browser.

class browser_history.generic.Browser(plat: browser_history.utils.Platform = None)

A generic class to support all major browsers with minimal configuration.

Currently, only browsers which save the history in SQLite files are supported.

To create a new browser type, the following class variables must be set.

  • name: A name for the browser. Not used anywhere except for logging and errors.

  • Paths: A path string, relative to the home directory, where the browsers data is saved. This path should be one level above the profile directories if they exist. At least one of the following must be set.

    • windows_path: browser path on Windows.

    • mac_path: browser path on Mac OS

    • linux_path: browser path on Linux

  • profile_support: (optional) boolean indicating whether the browser supports multiple profiles.

  • profile_dir_prefixes: (optional) list of possible prefixes for the profile directories. Keep empty to check all subdirectories in the browser path.

  • history_file: name of the (SQLite) file which stores the history.

  • history_SQL: SQL query required to extract history from the history_file. The query must return two columns: visit_time and url. The visit_time must be processed using the datetime function with the modifier localtime.

Parameters

plat (browser_history.utils.Platform) – the current platform. A value of None means the platform will be inferred from the system.

history(history_paths=None)

Returns history of all available profiles.

The returned datetimes are timezone-aware with the local timezone set by default.

The history files are first copied to a temporary location and then queried, this might lead to some additional overhead and results returned might not be the latest if the browser is in use. This is done because the SQlite files are locked by the browser when in use.

Parameters

history_paths (list(pathlib.Path)) – (optional) a list of history files.

Returns

List of tuples of a timestamp and corresponding URL

Return type

list(tuple(datetime.datetime, str))

history_path_profile(profile_dir: pathlib.Path) → pathlib.Path

Returns path of the history file for the given profile_dir

The profile_dir should be one of the outputs from profiles()

Parameters

profile_dir (pathlib.Path) – Profile directory (should be a single name, relative to history_dir)

Returns

path to history file of the profile

Return type

pathlib.Path

history_paths()

Returns a list of history file paths, for all profiles.

Return type

list(pathlib.Path)

history_profiles(profile_dirs)

Returns history of profiles given by profile_dirs.

Parameters

profile_dirs (list(str)) – List or iterable of profile directories. Can be obtained from profiles()

Returns

History of selected profiles

Return type

list(tuple(datetime.datetime, str))

profiles() → List[str]

Returns a list of profile directories

(TODO: fix this) The returned profiles include only the final name in the path.

Return type

list(str)