72 lines
2.5 KiB
Python
72 lines
2.5 KiB
Python
import json
|
|
import os
|
|
import time
|
|
|
|
from selenium import webdriver
|
|
from selenium.webdriver.chrome.options import Options
|
|
|
|
|
|
options = Options()
|
|
options.add_experimental_option("debuggerAddress", os.environ.get("WEHAGO_CHROME_DEBUGGER_ADDRESS", "127.0.0.1:9225"))
|
|
driver = webdriver.Chrome(options=options)
|
|
driver.set_script_timeout(10)
|
|
|
|
script = r"""
|
|
const body = Array.from(document.querySelectorAll('.rg-body')).find(el => String(el.$_view) === '75');
|
|
if (body) {
|
|
const r = body.getBoundingClientRect();
|
|
const x = r.left + 80, y = r.top + 85;
|
|
for (const type of ['mouseover','mousemove','mousedown','mouseup','click']) {
|
|
body.dispatchEvent(new MouseEvent(type,{bubbles:true,cancelable:true,view:window,clientX:x,clientY:y,button:0}));
|
|
}
|
|
}
|
|
const summarize = (obj) => {
|
|
if (!obj) return null;
|
|
let keys = [];
|
|
try { keys = Object.getOwnPropertyNames(obj).concat(Object.keys(obj)); } catch(e) {}
|
|
const funcs = Array.from(new Set(keys)).filter(k => {
|
|
try { return typeof obj[k] === 'function'; } catch(e) { return false; }
|
|
}).slice(0, 160);
|
|
const props = {};
|
|
for (const k of keys.slice(0, 100)) {
|
|
try {
|
|
const v = obj[k];
|
|
if (['string','number','boolean'].includes(typeof v)) props[k]=v;
|
|
} catch(e) {}
|
|
}
|
|
return {text:String(obj).slice(0,200), keys:Array.from(new Set(keys)).slice(0,200), funcs, props};
|
|
};
|
|
const active = Grids.getActiveGrid && Grids.getActiveGrid();
|
|
const handler = active && active.getHandler && active.getHandler();
|
|
const out = {
|
|
active: summarize(active),
|
|
handler: summarize(handler),
|
|
current: null,
|
|
itemCount: null,
|
|
columns: null,
|
|
rows: []
|
|
};
|
|
const targets = [active, handler].filter(Boolean);
|
|
for (const g of targets) {
|
|
if (!out.current) {
|
|
try { if (g.getCurrent) out.current = g.getCurrent(); } catch(e) { out.current = {error:String(e)}; }
|
|
}
|
|
if (!out.itemCount) {
|
|
try { if (g.getItemCount) out.itemCount = g.getItemCount(); } catch(e) {}
|
|
try { if (!out.itemCount && g.fullItemCount) out.itemCount = g.fullItemCount(); } catch(e) {}
|
|
}
|
|
if (!out.columns) {
|
|
try { if (g.getColumns) out.columns = g.getColumns().map(c => ({name:c.name, fieldName:c.fieldName, text:c.header && c.header.text})); } catch(e) {}
|
|
}
|
|
try {
|
|
if (g.getValues) {
|
|
for (let i=0; i<Math.min(10, out.itemCount || 10); i++) out.rows.push({i, values:g.getValues(i)});
|
|
break;
|
|
}
|
|
} catch(e) { out.rowsError = String(e); }
|
|
}
|
|
return out;
|
|
"""
|
|
print(json.dumps(driver.execute_script(script), ensure_ascii=False, indent=2)[:80000])
|
|
driver.quit()
|