Skip to content

Commit b36f53b

Browse files
improve screen/inner bypasses
Fixups, improvements, further work - previously: added css rules to return blanks outside our range - previously: fixed generic query for getting property to return `x` if outside range - the range limitations means we don't always get a bypass (when someone is lying): factors include - the real measurements - zoom (as you zoom in, the values returned are smaller and vice versa) - system scaling (not tested but this would be similar to zoom) - seems as if desktop's minimum width is now 450px (at normal system scaling/zoom) - will consider expanding the lower bounds to 400 or 350, but I think we need a new approach that if we haven't done a bypass, then we should use JS and css injection to bisect the real value - only needed if (I think), prototype lies shows that BS is going on - allows 1px less in the pseudo value as a match (due to using `min`), and upgrades it to match (which helps with computations) - the recalculated screen value at 100% uses common corrections - it already rounds to the nearest even number, but sometimes (when it uses the bypassed values, even when rounded by by 1px) it's off: this is due to using the device pixel ratio PoC which is not as accurate after six or so decimal places - the gLieBypassed is pushed the recalculated value - section metrics - stable in fullscreen (luckily FS is not all 0,0 coordinates) - removed compare metrics - fixes inconsistencies to make it stable in FS - can't use them anyway: screen might be different from the rest due to recalculated-100%-zoom value, etc - this simplifies the logic: just return screen + coordinates-match for now - added screen prototype lies if we failed to bypass More to do though
1 parent 053dea7 commit b36f53b

File tree

1 file changed

+110
-98
lines changed

1 file changed

+110
-98
lines changed

js/screen.js

+110-98
Original file line numberDiff line numberDiff line change
@@ -698,11 +698,10 @@ function get_line_scrollbar(runtype) {
698698
let w = (window.innerWidth-vw)
699699
let pseudoW = getElementProp("#D","content",":before")
700700
if (pseudoW !== "x") {
701-
pseudoW = pseudoW * 1
702-
w = pseudoW-vw
701+
if (pseudoW == w-1) {pseudoW = w} // allow for min-
702+
w = (pseudoW * 1)-vw
703703
}
704704
let wZoom = w
705-
706705
// section metric
707706
if (w > 0) {dScrollbar = "not zero"} else {dScrollbar = "zero"}
708707

@@ -1663,12 +1662,10 @@ function get_resources() {
16631662
}
16641663

16651664
function get_screen_metrics(runtype) {
1666-
let t0 = performance.now(),
1667-
res = []
1665+
let res = []
16681666

16691667
//trap resize event
16701668
if (runtype !== "load" && runtype !== "screen") {runtype = "resize"}
1671-
16721669
// this triggers zoom/viewport when not page load
16731670
// but ignore viewport on resize: which is called by scrollbar
16741671
// nothing else needs to wait here for any results
@@ -1681,13 +1678,12 @@ function get_screen_metrics(runtype) {
16811678
}
16821679
})
16831680
}
1684-
1685-
// temp so I can see the new viewport/scrollbar
1681+
// resize to auto-update lineheight/scrollbar
16861682
if (runtype == "resize") {
16871683
get_line_scrollbar("resize")
16881684
}
16891685

1690-
// measure
1686+
// MEASURE: ToDo: catch errors
16911687
let w1 = screen.width, h1 = screen.height,
16921688
w2 = screen.availWidth, h2 = screen.availHeight,
16931689
w3 = window.outerWidth, h3 = window.outerHeight,
@@ -1696,92 +1692,32 @@ function get_screen_metrics(runtype) {
16961692
p3 = screen.availLeft, p4 = screen.availTop,
16971693
p5 = window.screenX, p6 = window.screenY,
16981694
p7 = window.mozInnerScreenX, p8 = window.mozInnerScreenY
1699-
1700-
let innerW = getElementProp("#D","content",":before"),
1701-
innerH = getElementProp("#D","content",":after")
1702-
if (innerW !== "x" && innerH !== "x") {
1703-
innerW = innerW * 1
1704-
innerH = innerH.slice(3) * 1
1705-
if (innerW !== w || innerH !== h) {
1706-
w = innerW
1707-
h = innerH
1708-
if (gRun) {
1709-
gLiesKnown.push("screen:inner window")
1710-
gLiesBypassed.push("screen:inner window:"+ w +" x "+ h)
1711-
}
1712-
}
1713-
}
1714-
1715-
let screenW = getElementProp("#S","content",":before"),
1716-
screenH = getElementProp("#S","content",":after")
1717-
if (screenW !== "x" && screenH !== "x") {
1718-
screenW = screenW * 1
1719-
screenH = screenH.slice(3) * 1
1720-
if (screenW !== w1 || screenH !== h1) {
1721-
w1 = screenW
1722-
h1 = screenH
1723-
if (gRun) {
1724-
gLiesKnown.push("screen:screen")
1725-
gLiesBypassed.push("screen:screen:"+ w1 +" x "+ h1)
1726-
}
1727-
}
1728-
}
1695+
// temp lies
1696+
//w1 = 1920; h1 = 1080
1697+
//w2 = 1920, h2 = 1080,
1698+
//w3 = 1920, h3 = 1080,
1699+
//w = 1920; h = 1080
17291700

17301701
let mInner = w +" x "+ h,
17311702
mOuter = w3 +" x "+ h3,
17321703
mScreen = w1 +" x "+ h1,
17331704
mAvailable = w2 +" x "+ h2
1705+
//console.debug("reported", mInner, mScreen)
17341706

1707+
// DISPLAY
17351708
dom.ScrRes = mScreen +" ("+ p1 +","+ p2 +")"
17361709
dom.ScrAvail = mAvailable +" ("+ p3 +","+ p4 +")"
17371710
dom.WndOut = mOuter +" ("+ p5 +","+ p6 +")"
1738-
1739-
// x/y
1740-
let items = [p1,p2,p3,p4,p5,p6,p7,p8],
1741-
isXY = true
1711+
dom.WndIn.innerHTML = mInner +" ("+ p7 +","+ p8 +")"
1712+
// NOTATE
1713+
let items = [p1,p2,p3,p4,p5,p6,p7,p8], isXY = true
17421714
for (let i=0; i < items.length; i++) {if (items[i] != 0) {isXY = false}}
1743-
// fs
1744-
let isFS = false
1745-
try {isFS = window.fullScreen; dom.fsState = isFS} catch(e) {dom.fsState.innerHTML = zB0}
1746-
1747-
// section hash
1748-
// ToDo: needs better logic + prototype lie checks: e.g.
1749-
// if in FS all but available should be the same (ignore available)
1750-
// if not in FS all 4 values should be different?
1751-
if (runtype == "load" || runtype == "screen") {
1752-
// make screen zoom resistant
1753-
let mScreen2 = ""
1754-
if (isFF && Number.isInteger(jsZoom) && isOS !== "android") {
1755-
if (jsZoom !== 100) {
1756-
if (Number(dpr2) !== NaN && Number(dpr2) > 0) {
1757-
mScreen2 = 2 * Math.round((w1 * dpr2)/2) +" x "+ 2 * Math.round((h1 * dpr2)/2)
1758-
}
1759-
}
1760-
}
1761-
// note: FS would make these true
1762-
res.push("coordinates_zero:"+ isXY)
1763-
let match = (mScreen == mAvailable)
1764-
res.push("match_screen+available:"+ match)
1765-
match = (mInner == mOuter)
1766-
res.push("match_inner+outer:"+ match)
1767-
match = (mInner == mScreen)
1768-
res.push("match_inner+screen:"+ match)
1769-
1770-
// ToDo: improve (see above) and return screen + available screen
1771-
if (isFS || mInner !== mScreen) {
1772-
res.push("screen:"+ (mScreen2 == "" ? mScreen : mScreen2))
1773-
} else {
1774-
res.push("screen:spoofed")
1775-
}
1776-
}
1777-
1778-
// RFP
17791715
if (isFF) {
1780-
// size
1716+
// sizes
17811717
let m1 = true, m2 = true, r = "", c = "#ff4f4f"
1782-
if (w1 +"x"+ h1 !== w2 +"x"+ h2) {m1 = false}
1783-
else if (w2 +"x"+ h2 !== w3 +"x"+ h3) {m1 = false}
1784-
else if (w3 +"x"+ h3 !== w +"x"+ h) {m1 = false}
1718+
if (mScreen !== mAvailable) {m1 = false}
1719+
else if (mAvailable !== mOuter) {m1 = false}
1720+
else if (mOuter !== mInner) {m1 = false}
17851721
r = (m1 ? sg : sb) +"[sizes match x4]"+ sc
17861722
// x/y
17871723
r += " +"+ (isXY ? sg : sb) +"[0,0 x4]"+ sc
@@ -1790,25 +1726,101 @@ function get_screen_metrics(runtype) {
17901726
if (m1 && m2) {c = "#8cdc8c"}
17911727
items = document.getElementsByClassName("group")
17921728
for (let i=0; i < items.length; i++) {items[i].style.color = c}
1729+
// inner: LB/NW
1730+
if (isOS !== "android" && jsZoom == 100) {
1731+
dom.WndIn.innerHTML = mInner +" ("+ p7 +","+ p8 +")"+ return_lb_nw(w,h)
1732+
}
17931733
}
1734+
// THE REST
1735+
get_orientation(runtype) // nothing stable
1736+
get_mm_metrics(runtype) // not reliable due to extension APIs
17941737

1795-
// inner
1796-
let strTemp = w +" x "+ h +" ("+ p7 +","+ p8 +")"
1797-
if (isOS == "android") {
1798-
dom.WndIn = strTemp
1799-
} else {
1800-
// LB/NW
1801-
if (isFF) {
1802-
if (jsZoom == 100) {strTemp += return_lb_nw(w,h)}
1738+
// METRICS
1739+
if (runtype !== "resize") {
1740+
// allow 1px less due to min-
1741+
// inner
1742+
let innerW = getElementProp("#D","content",":before"),
1743+
innerH = getElementProp("#D","content",":after")
1744+
if (innerW !== "x" && innerH !== "x") {
1745+
innerW = innerW * 1
1746+
innerH = innerH.slice(3) * 1
1747+
// round up 1px
1748+
if (innerW == w-1) {innerW = w}
1749+
if (innerH == h-1) {innerH = h}
1750+
if (innerW !== w || innerH !== h) {
1751+
if (gRun) {
1752+
gLiesKnown.push("screen:inner window")
1753+
gLiesBypassed.push("screen:inner window:"+ innerW +" x "+ innerH)
1754+
}
1755+
}
1756+
}
1757+
// screen
1758+
let screenW = getElementProp("#S","content",":before"),
1759+
screenH = getElementProp("#S","content",":after"),
1760+
screenBypass = false
1761+
if (screenW !== "x" && screenH !== "x") {
1762+
screenW = screenW * 1
1763+
screenH = screenH.slice(3) * 1
1764+
// round up 1px: helps 100%-zoom recalc
1765+
if (screenW == w1-1) {screenW = w1}
1766+
if (screenH == h1-1) {screenH = h1}
1767+
if (screenW !== w1 || screenH !== h1) {
1768+
screenBypass = true
1769+
w1 = screenW
1770+
h1 = screenH
1771+
mScreen = w1 +" x "+ h1
1772+
if (gRun) {gLiesKnown.push("screen:screen")}
1773+
}
1774+
}
1775+
// debug missing ranges
1776+
//console.debug(jsZoom+ "%", innerW, innerH, screenW, screenH)
1777+
1778+
// ToDo: HARDEN: due to zoom and limited ranges: often a css pseudo value can be invalid
1779+
// since this is excluded in resize events, we can afford to spend some perf to
1780+
// inject bisecting css rules
1781+
1782+
// FS
1783+
let isFS = false
1784+
try {isFS = window.fullScreen; dom.fsState = isFS} catch(e) {dom.fsState.innerHTML = zB0}
1785+
// calc screen at 100%
1786+
if (isFF && Number.isInteger(jsZoom) && isOS !== "android") {
1787+
if (jsZoom !== 100) {
1788+
if (Number(dpr2) !== NaN && Number(dpr2) > 0) {
1789+
let w100 = 2 * Math.round((w1 * dpr2)/2)
1790+
let h100 = 2 * Math.round((h1 * dpr2)/2)
1791+
// rounding fixups
1792+
let common = [360,600,640,720,768,800,810,834,864,900,1024,1050,1080,1112,1152,1200,1280,1360,1366,1440,1536,1600,1680,1920,2048,2560,]
1793+
for (let i=0; i < common.length; i++) {
1794+
let real = common[i]
1795+
if (w100 >= real-2 && w100 <= real+2) {
1796+
//if (w100 !== real) {console.debug("changed width", w100, "to", real, jsZoom +"%")} // temp debug
1797+
w100 = real
1798+
}
1799+
if (h100 >= real-2 && h100 <= real+2) {
1800+
//if (h100 !== real) {console.debug("changed height", h100, "to", real, jsZoom +"%")} // temp debug
1801+
h100 = real
1802+
}
1803+
}
1804+
mScreen = w100 +" x "+ h100
1805+
//console.debug("recalculated 100% zoom screen", mScreen)
1806+
}
1807+
}
18031808
}
1804-
dom.WndIn.innerHTML = strTemp
1805-
}
1806-
// the rest
1807-
get_orientation(runtype)
1808-
get_mm_metrics(runtype)
18091809

1810-
// section metrics
1811-
if (runtype == "load" || runtype == "screen") {
1810+
// metrics: don't let FS affect stability, no comparisons due to bypasses and recalc at 100% zoom
1811+
res.push("coordinates_zero:"+ isXY) // FF: mozInnerScreenY is not zero at FS
1812+
if (screenBypass) {
1813+
// bypass
1814+
res.push("screen:"+ mScreen)
1815+
if (gRun) {gLiesBypassed.push("screen:screen:"+ mScreen)}
1816+
} else {
1817+
// fall back to prototype
1818+
let scrLies = false
1819+
if (protoLies.includes("Screen.width")) {scrLies = true}
1820+
if (protoLies.includes("Screen.height")) {scrLies = true}
1821+
res.push("screen:"+ (scrLies ? "fake" : mScreen))
1822+
}
1823+
//console.debug("fullscreen:", jsZoom + " %", isFS, "\n - "+ sha1(res) + "\n - " + res.join("\n - "))
18121824
return(res)
18131825
}
18141826
}

0 commit comments

Comments
 (0)