Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Use Selenium as a WebView in the browser #642

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ dependencies {
implementation(libs.cron4j)

implementation(libs.cronUtils)

implementation("org.seleniumhq.selenium:selenium-java:4.11.0")
implementation("me.friwi:jcefmaven:110.0.25.1")
}

application {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ object CFClearance {
}

// ref: https://github.com/vvanglro/cf-clearance/blob/44124a8f06d8d0ecf2bf558a027082ff88dab435/cf_clearance/stealth.py#L76
private fun applyStealthInitScripts(page: Page) {
fun applyStealthInitScripts(page: Page) {
for (script in stealthInitScripts) {
page.addInitScript(script)
}
Expand Down
6 changes: 6 additions & 0 deletions server/src/main/kotlin/suwayomi/tachidesk/global/GlobalAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ package suwayomi.tachidesk.global
import io.javalin.apibuilder.ApiBuilder.get
import io.javalin.apibuilder.ApiBuilder.patch
import io.javalin.apibuilder.ApiBuilder.path
import io.javalin.apibuilder.ApiBuilder.ws
import suwayomi.tachidesk.global.controller.GlobalMetaController
import suwayomi.tachidesk.global.controller.SettingsController
import suwayomi.tachidesk.global.controller.WebViewController

object GlobalAPI {
fun defineEndpoints() {
Expand All @@ -23,5 +25,9 @@ object GlobalAPI {
get("about", SettingsController.about)
get("check-update", SettingsController.checkUpdate)
}
path("webview") {
get("", WebViewController.webview)
ws("", WebViewController::webviewWS)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package suwayomi.tachidesk.global.controller

/*
* Copyright (C) Contributors to the Suwayomi project
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

import io.javalin.http.ContentType
import io.javalin.http.HttpCode
import io.javalin.websocket.WsConfig
import suwayomi.tachidesk.global.impl.WebView
import suwayomi.tachidesk.server.util.handler
import suwayomi.tachidesk.server.util.withOperation

object WebViewController {
/** returns some static info about the current app build */
val webview = handler(
documentWith = {
withOperation {
summary("WebView")
description("Opens and browses WebView")
}
},
behaviorOf = { ctx ->
ctx.contentType(ContentType.TEXT_HTML)
ctx.result(javaClass.getResourceAsStream("/selenium.html")!!)
},
withResults = {
mime<String>(HttpCode.OK, "text/html")
}
)

fun webviewWS(ws: WsConfig) {
ws.onConnect { ctx ->
WebView.addClient(ctx)
}
ws.onMessage { ctx ->
WebView.handleRequest(ctx)
}
ws.onClose { ctx ->
WebView.removeClient(ctx)
}
}
}
Loading
Loading