Hide navigation sidebar
Hide table of contents sidebar
Back to top
Toggle table of contents sidebar

# ServiceWorker

This CDP domain is experimental.

- Types

- Commands

- Events

## Types

Generally, you do not need to instantiate CDP types yourself. Instead, the API creates objects for you as return values from commands, and then you can use those objects as arguments to other commands.

class RegistrationID

class ServiceWorkerRegistration(registration_id, scope_url, is_deleted)

  ServiceWorker registration.

  registration_id: `RegistrationID`
  scope_url: `str`
  is_deleted: `bool`

class ServiceWorkerVersionRunningStatus(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
  STOPPED = 'stopped'
  STARTING = 'starting'
  RUNNING = 'running'
  STOPPING = 'stopping'

class ServiceWorkerVersionStatus(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
  NEW = 'new'
  INSTALLING = 'installing'
  INSTALLED = 'installed'
  ACTIVATING = 'activating'
  ACTIVATED = 'activated'
  REDUNDANT = 'redundant'

class ServiceWorkerVersion(version_id, registration_id, script_url, running_status, status, script_last_modified=None, script_response_time=None, controlled_clients=None, target_id=None, router_rules=None)

  ServiceWorker version.

  version_id: `str`
  registration_id: `RegistrationID`
  script_url: `str`
  running_status: `ServiceWorkerVersionRunningStatus`
  status: `ServiceWorkerVersionStatus`
  script_last_modified: `Optional`[`float`] = None

    The Last-Modified header value of the main script.

  script_response_time: `Optional`[`float`] = None

    The time at which the response headers of the main script were received from the server. For cached script it is the last time the cache entry was validated.

  controlled_clients: `Optional`[`List`[`TargetID`]] = None
  target_id: `Optional`[`TargetID`] = None
  router_rules: `Optional`[`str`] = None

class ServiceWorkerErrorMessage(error_message, registration_id, version_id, source_url, line_number, column_number)

  ServiceWorker error message.

  error_message: `str`
  registration_id: `RegistrationID`
  version_id: `str`
  source_url: `str`
  line_number: `int`
  column_number: `int`

## Commands

Each command is a generator function. The return type `Generator[x, y, z]` indicates that the generator yields arguments of type `x`, it must be resumed with an argument of type `y`, and it returns type `z`. In this library, types `x` and `y` are the same for all commands, and `z` is the return type you should pay attention to. For more information, see Getting Started: Commands.

deliver_push_message(origin, registration_id, data)
  Parameters:

    - origin (`str`) –

    - registration_id (`RegistrationID`) –

    - data (`str`) –

  Return type:

    `Generator`[`Dict`[`str`, `Any`], `Dict`[`str`, `Any`], `None`]

disable()
  Return type:

    `Generator`[`Dict`[`str`, `Any`], `Dict`[`str`, `Any`], `None`]

dispatch_periodic_sync_event(origin, registration_id, tag)
  Parameters:

    - origin (`str`) –

    - registration_id (`RegistrationID`) –

    - tag (`str`) –

  Return type:

    `Generator`[`Dict`[`str`, `Any`], `Dict`[`str`, `Any`], `None`]

dispatch_sync_event(origin, registration_id, tag, last_chance)
  Parameters:

    - origin (`str`) –

    - registration_id (`RegistrationID`) –

    - tag (`str`) –

    - last_chance (`bool`) –

  Return type:

    `Generator`[`Dict`[`str`, `Any`], `Dict`[`str`, `Any`], `None`]

enable()
  Return type:

    `Generator`[`Dict`[`str`, `Any`], `Dict`[`str`, `Any`], `None`]

set_force_update_on_page_load(force_update_on_page_load)
  Parameters:

    force_update_on_page_load (`bool`) –

  Return type:

    `Generator`[`Dict`[`str`, `Any`], `Dict`[`str`, `Any`], `None`]

skip_waiting(scope_url)
  Parameters:

    scope_url (`str`) –

  Return type:

    `Generator`[`Dict`[`str`, `Any`], `Dict`[`str`, `Any`], `None`]

start_worker(scope_url)
  Parameters:

    scope_url (`str`) –

  Return type:

    `Generator`[`Dict`[`str`, `Any`], `Dict`[`str`, `Any`], `None`]

stop_all_workers()
  Return type:

    `Generator`[`Dict`[`str`, `Any`], `Dict`[`str`, `Any`], `None`]

stop_worker(version_id)
  Parameters:

    version_id (`str`) –

  Return type:

    `Generator`[`Dict`[`str`, `Any`], `Dict`[`str`, `Any`], `None`]

unregister(scope_url)
  Parameters:

    scope_url (`str`) –

  Return type:

    `Generator`[`Dict`[`str`, `Any`], `Dict`[`str`, `Any`], `None`]

update_registration(scope_url)
  Parameters:

    scope_url (`str`) –

  Return type:

    `Generator`[`Dict`[`str`, `Any`], `Dict`[`str`, `Any`], `None`]

## Events

Generally, you do not need to instantiate CDP events yourself. Instead, the API creates events for you and then you use the event’s attributes.

class WorkerErrorReported(error_message)
  error_message: `ServiceWorkerErrorMessage`

class WorkerRegistrationUpdated(registrations)
  registrations: `List`[`ServiceWorkerRegistration`]

class WorkerVersionUpdated(versions)
  versions: `List`[`ServiceWorkerVersion`]