main.com.enniovisco.tracking.commands.MetadataCollector.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of webmonitor Show documentation
Show all versions of webmonitor Show documentation
A formal approach to monitoring web pages as spatio-temporal traces.
The newest version!
package com.enniovisco.tracking.commands
import io.github.oshai.kotlinlogging.*
class MetadataCollector(cmdExec: (String) -> Any) : BrowserCommand() {
private val layoutVpWidth: String
private val layoutVpHeight: String
private val visualVpWidth: String
private val visualVpHeight: String
private val log = KotlinLogging.logger {}
init {
/*
Document areas considered by the page, including unreachable ones.
They are not tracked at all at the moment
*/
// Layout Viewport: Scrollable area
val layoutVp = "return document.documentElement"
layoutVpWidth = cmdExec("${layoutVp}.scrollWidth").toString()
layoutVpHeight = cmdExec("${layoutVp}.scrollHeight").toString()
log.info { "Layout Viewport: ${layoutVpWidth}x${layoutVpHeight}" }
// Visual Viewport: physical screen
visualVpWidth = cmdExec("return window.innerWidth;").toString()
visualVpHeight = cmdExec("return window.innerHeight;").toString()
log.info { "Visual Viewport: ${visualVpWidth}x${visualVpHeight}" }
}
override fun dump(target: MutableMap) {
target["lvp_width"] = layoutVpWidth
target["lvp_height"] = layoutVpHeight
target["vvp_width"] = visualVpWidth
target["vvp_height"] = visualVpHeight
}
}