Skip to content

Commit 9237786

Browse files
committed
refactor: replace Clock.System.now with dateNow for WASM JS timestamp handling #532
- Removed `kotlinx.datetime.Clock` dependency and replaced it with a JavaScript-native `dateNow` function in `PageStateExtractor` and `BrowserActionExecutor`.
1 parent ee1e345 commit 9237786

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

mpp-core/src/wasmJsMain/kotlin/cc/unitmesh/agent/e2etest/executor/BrowserActionExecutor.wasmJs.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cc.unitmesh.agent.e2etest.executor
22

33
import cc.unitmesh.agent.e2etest.model.*
4-
import kotlinx.datetime.Clock
54

65
/**
76
* WASM JS implementation of BrowserActionExecutor.
@@ -60,4 +59,7 @@ class WasmJsBrowserActionExecutor private constructor(
6059

6160
actual fun createBrowserActionExecutor(config: BrowserExecutorConfig): BrowserActionExecutor? = null
6261

63-
internal actual fun currentTimeMillis(): Long = Clock.System.now().toEpochMilliseconds()
62+
@JsFun("() => Date.now()")
63+
private external fun dateNow(): Double
64+
65+
internal actual fun currentTimeMillis(): Long = dateNow().toLong()

mpp-core/src/wasmJsMain/kotlin/cc/unitmesh/agent/e2etest/perception/PageStateExtractor.wasmJs.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package cc.unitmesh.agent.e2etest.perception
22

33
import cc.unitmesh.agent.e2etest.model.*
4-
import kotlinx.datetime.Clock
4+
5+
@JsFun("() => Date.now()")
6+
private external fun dateNow(): Double
57

68
/**
79
* WASM JS implementation of PageStateExtractor.
8-
*
10+
*
911
* Uses browser APIs or Playwright MCP server.
10-
*
12+
*
1113
* @see <a href="https://github.com/phodal/auto-dev/issues/532">Issue #532</a>
1214
*/
1315
actual interface PageStateExtractor {
@@ -31,16 +33,16 @@ actual interface PageStateExtractor {
3133
class WasmJsPageStateExtractor(
3234
private val config: PageStateExtractorConfig
3335
) : PageStateExtractor {
34-
36+
3537
override val isAvailable: Boolean = false
36-
38+
3739
override suspend fun extractPageState(): PageState {
3840
return PageState(
3941
url = "",
4042
title = "",
4143
viewport = Viewport(config.viewportWidth, config.viewportHeight),
4244
actionableElements = emptyList(),
43-
capturedAt = Clock.System.now().toEpochMilliseconds()
45+
capturedAt = dateNow().toLong()
4446
)
4547
}
4648

0 commit comments

Comments
 (0)