Browser Functionality

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

class browser_history.generic.Browser(plat=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.

These following class variable can optionally be set:

Parameters

plat (Optional[Platform]) – the current platform. A value of None means the platform will be inferred from the system.

Examples:

>>> class CustomBrowser(Browser):
...     name = 'custom browser'
...     aliases = ('custom-browser', 'customhtm')
...     history_file = 'history_file'
...     history_SQL = """
...         SELECT
...             url
...         FROM
...             history_visits
...     """
...     linux_path = 'browser'
...
... vars(CustomBrowser())
{'profile_dir_prefixes': [], 'history_dir': PosixPath('/home/username/browser')}
_local_tz: Optional[datetime.tzinfo] = datetime.timezone(datetime.timedelta(0), 'UTC')

Gets a datetime object of the current time as per the users timezone.

aliases: tuple = ()

Gets possible names (lower-cased) used to refer to the browser type. Useful for making the browser detectable as a default browser which may be named in various forms on different platforms. Do not include name in this list

bookmarks_file: Optional[str] = None

Name of the (SQLite, JSON or PLIST) file which stores the bookmarks.

bookmarks_parser(bookmark_path)

A function to parse bookmarks and convert to readable format.

bookmarks_path_profile(profile_dir)

Returns path of the bookmark 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)

Return type

Optional[Path]

Returns

path to bookmark file of the profile

fetch_bookmarks(bookmarks_paths=None, sort=True, desc=False)

Returns bookmarks of all available profiles stored in SQL or JSON or plist.

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

The bookmark 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
  • bookmarks_paths (list(pathlib.Path)) – (optional) a list of bookmark files.

  • sort (boolean) – (optional) flag to specify if the output should be sorted. Default value set to True.

  • desc – (optional) flag to specify asc/desc (Applicable if sort is True) Default value set to False.

Returns

Object of class browser_history.generic.Outputs with the attribute bookmarks set to a list of (timestamp, url, title, folder) tuples

Return type

browser_history.generic.Outputs

fetch_history(history_paths=None, sort=True, desc=False)

Returns history of all available profiles stored in SQL.

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.

  • sort (boolean) – (optional) flag to specify if the output should be sorted. Default value set to True.

  • desc – (optional) flag to specify asc/desc (Applicable if sort is True) Default value set to False.

Returns

Object of class browser_history.generic.Outputs with the data member histories set to list(tuple(datetime.datetime, str)). If the browser is not installed, this object will be empty.

Return type

browser_history.generic.Outputs

abstract property history_SQL: str

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.

Return type

str

history_dir: pathlib.Path

History directory.

abstract property history_file: str

Name of the (SQLite) file which stores the history.

Return type

str

history_path_profile(profile_dir)

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)

Return type

Optional[Path]

Returns

path to history file of the profile

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

Object of class browser_history.generic.Outputs with the data member histories set to list(tuple(datetime.datetime, str))

Return type

browser_history.generic.Outputs

classmethod is_supported()

Checks whether the browser is supported on current platform

Returns

True if browser is supported on current platform else False

Return type

boolean

linux_path: Optional[str] = None

browser path on Linux.

mac_path: Optional[str] = None

browser path on Mac OS.

abstract property name: str

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

Return type

str

paths(profile_file)

Returns a list of file paths, for all profiles.

Return type

list(pathlib.Path)

profile_dir_prefixes: Optional[List[Any]] = None

List of possible prefixes for the profile directories. Keep empty to check all subdirectories in the browser path.

profile_support: bool = False

Boolean indicating whether the browser supports multiple profiles.

profiles(profile_file)

Returns a list of profile directories. If the browser is supported on the current platform but is not installed an empty list will be returned

Parameters

profile_file (str) – file to search for in the profile directories. This should be either history_file or bookmarks_file.

Return type

list(str)

windows_path: Optional[str] = None

browser path on Windows.