Updated script that can be controled by Nodejs web app

This commit is contained in:
mac OS
2024-11-25 12:24:18 +07:00
parent c440eda1f4
commit 8b0ab2bd3a
8662 changed files with 1803808 additions and 34 deletions

View File

@ -0,0 +1,16 @@
# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

View File

@ -0,0 +1,77 @@
# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.options import ArgOptions
class Options(ArgOptions):
KEY = "webkitgtk:browserOptions"
def __init__(self) -> None:
super().__init__()
self._binary_location = ""
self._overlay_scrollbars_enabled = True
@property
def binary_location(self) -> str:
""":Returns: The location of the browser binary otherwise an empty
string."""
return self._binary_location
@binary_location.setter
def binary_location(self, value: str) -> None:
"""Allows you to set the browser binary to launch.
:Args:
- value : path to the browser binary
"""
self._binary_location = value
@property
def overlay_scrollbars_enabled(self):
""":Returns: Whether overlay scrollbars should be enabled."""
return self._overlay_scrollbars_enabled
@overlay_scrollbars_enabled.setter
def overlay_scrollbars_enabled(self, value) -> None:
"""Allows you to enable or disable overlay scrollbars.
:Args:
- value : True or False
"""
self._overlay_scrollbars_enabled = value
def to_capabilities(self):
"""Creates a capabilities with all the options that have been set and
returns a dictionary with everything."""
caps = self._caps
browser_options = {}
if self.binary_location:
browser_options["binary"] = self.binary_location
if self.arguments:
browser_options["args"] = self.arguments
browser_options["useOverlayScrollbars"] = self.overlay_scrollbars_enabled
caps[Options.KEY] = browser_options
return caps
@property
def default_capabilities(self):
return DesiredCapabilities.WEBKITGTK.copy()

View File

@ -0,0 +1,60 @@
# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import typing
import warnings
from selenium.webdriver.common import service
DEFAULT_EXECUTABLE_PATH: str = "WebKitWebDriver"
class Service(service.Service):
"""A Service class that is responsible for the starting and stopping of
`WPEWebDriver`.
:param executable_path: install path of the WebKitWebDriver executable, defaults to `WebKitWebDriver`.
:param port: Port for the service to run on, defaults to 0 where the operating system will decide.
:param service_args: (Optional) List of args to be passed to the subprocess when launching the executable.
:param log_output: (Optional) File path for the file to be opened and passed as the subprocess stdout/stderr handler.
:param env: (Optional) Mapping of environment variables for the new process, defaults to `os.environ`.
"""
def __init__(
self,
executable_path: str = DEFAULT_EXECUTABLE_PATH,
port: int = 0,
log_path: typing.Optional[str] = None,
log_output: typing.Optional[str] = None,
service_args: typing.Optional[typing.List[str]] = None,
env: typing.Optional[typing.Mapping[str, str]] = None,
**kwargs,
) -> None:
self.service_args = service_args or []
if log_path is not None:
warnings.warn("log_path is deprecated, use log_output instead", DeprecationWarning, stacklevel=2)
log_path = open(log_path, "wb")
log_output = open(log_output, "wb") if log_output else None
super().__init__(
executable_path=executable_path,
port=port,
log_output=log_path or log_output,
env=env,
**kwargs,
)
def command_line_args(self) -> typing.List[str]:
return ["-p", f"{self.port}"] + self.service_args

View File

@ -0,0 +1,60 @@
# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import http.client as http_client
from selenium.webdriver.common.driver_finder import DriverFinder
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
from .options import Options
from .service import Service
class WebDriver(RemoteWebDriver):
"""Controls the WebKitGTKDriver and allows you to drive the browser."""
def __init__(
self,
options=None,
service: Service = None,
):
"""Creates a new instance of the WebKitGTK driver.
Starts the service and then creates new instance of WebKitGTK Driver.
:Args:
- options : an instance of WebKitGTKOptions
- service : Service object for handling the browser driver if you need to pass extra details
"""
options = options if options else Options()
self.service = service if service else Service()
self.service.path = DriverFinder(self.service, options).get_driver_path()
self.service.start()
super().__init__(command_executor=self.service.service_url, options=options)
self._is_remote = False
def quit(self):
"""Closes the browser and shuts down the WebKitGTKDriver executable
that is started when starting the WebKitGTKDriver."""
try:
super().quit()
except http_client.BadStatusLine:
pass
finally:
self.service.stop()