-
Notifications
You must be signed in to change notification settings - Fork 3
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
Sometimes the script stops working (in Chrome or after the update) #200
Comments
https://erosman.github.io/firemonkey/src/content/help.html
Similar prerequisites, interesting |
// ==UserScript==
// @name Bug
// @version 1337
// @author deevroman
// @match https://www.openstreetmap.org/*
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_info
// @sandbox JavaScript
// @run-at document-start
// ==/UserScript==
const mapPositionsHistory = []
const mapPositionsNextHistory = []
function runPositionTracker() {
setInterval(() => {
if (!getMap()) return
try {
const m = getMap()
const bound = [
[m.getBounds().getSouth(), m.getBounds().getWest()],
[m.getBounds().getNorth(), m.getBounds().getEast()]
]
if (JSON.stringify(mapPositionsHistory[mapPositionsHistory.length - 1]) === JSON.stringify(bound)) {
return;
}
// in case of a transition between positions
// via timeout?
if (JSON.stringify(mapPositionsNextHistory[mapPositionsNextHistory.length - 1]) === JSON.stringify(bound)) {
return;
}
mapPositionsNextHistory.length = 0
mapPositionsHistory.push(bound)
if (mapPositionsHistory.length > 100) {
mapPositionsHistory.shift()
mapPositionsHistory.shift()
}
} catch {
alert("Please, reload page")
}
}, 1000);
}
var map = null
var getMap = null
//var getWindow = null
function mapHook() {
console.log("start map intercepting")
console.log(unsafeWindow.L)
unsafeWindow.L.Map.addInitHook(exportFunction((function () {
if (this._container?.id === "map") {
//unsafeWindow.map = this;
console.log("map intercepted");
alert("ok")
}
}), unsafeWindow)
)
}
unsafeWindow.mapHook = exportFunction(mapHook, unsafeWindow)
unsafeWindow.mapHook()
if (unsafeWindow.map instanceof HTMLElement) {
console.error("Please, reload page, if something doesn't work")
}
getMap = () => unsafeWindow.map
//getWindow = () => unsafeWindow
//map = getMap() |
https://www.tampermonkey.net/documentation.php#meta:run_at
As expected, although it is not clear why everything starts working in an open console. I probably need to think about a workaround instead of trying to debug it. |
Solved with a dirty hack. Add another hook for |
For some reason, in my Chrome on macOS, the script sometimes does not show objects on the map. In Firefox, this occurs only after updating the script, and in this situation it is enough to reload the tab. And in Chrome, sometimes even restarting the browser doesn’t help.
Sometimes I notice that this happens when I’m logged out of OSM and logging in helps (wtf?). The map display also starts working if you just open the browser console. (WTF?)
The source of the problem is how the script gets the Leaflet map object. Now this is done with a dirty hack by adding a hook to Leaflet:
better-osm-org/better-osm-org.user.js
Lines 11671 to 11714 in 3597713
How can I try to solve the problem:
The text was updated successfully, but these errors were encountered: