Spaces:
Sleeping
Sleeping
File size: 3,612 Bytes
7c87115 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | """
Script to inspect NotebookLM DOM for file upload selectors.
"""
import time
import json
from pathlib import Path
from notebooklm_tools.utils.cdp import (
launch_chrome,
get_debugger_url,
find_or_create_notebooklm_page,
execute_cdp_command,
get_page_html,
navigate_to_url
)
from notebooklm_tools.core.auth import load_cached_tokens
def inspect_dom():
print("Launching Chrome for DOM inspection...")
if not launch_chrome(headless=False):
print("Failed to launch Chrome")
return
tokens = load_cached_tokens()
if not tokens:
print("No tokens found. Login first.")
return
print("Connecting to Chrome...")
time.sleep(2)
page = find_or_create_notebooklm_page()
if not page:
print("Failed to find/create page")
return
ws_url = page.get("webSocketDebuggerUrl")
print(f"Connected to page: {page.get('title')}")
print("Creating test notebook for inspection...")
from notebooklm_tools.core.client import NotebookLMClient
client = NotebookLMClient(tokens.cookies)
try:
notebook = client.create_notebook("Upload Inspection Test")
print(f"Created notebook: {notebook.id}")
notebook_url = f"https://notebooklm.google.com/notebook/{notebook.id}"
print(f"Navigating to: {notebook_url}")
navigate_to_url(ws_url, notebook_url)
time.sleep(5) # Wait for load
except Exception as e:
print(f"Failed to create/nav to notebook: {e}")
# Fallback to existing page
pass
# Get HTML
print("Capturing HTML...")
html = get_page_html(ws_url)
# Save to file for analysis
Path("dom_dump.html").write_text(html)
print("Saved to dom_dump.html")
# Analyze for potential upload selectors
print("\nSearching for file inputs...")
# Check for file input
result = execute_cdp_command(ws_url, "Runtime.evaluate", {
"expression": "document.querySelectorAll('input[type=file]').length"
})
count = result.get("result", {}).get("value", 0)
print(f"Found {count} file inputs")
if count > 0:
# Get details
result = execute_cdp_command(ws_url, "Runtime.evaluate", {
"expression": """
Array.from(document.querySelectorAll('input[type=file]')).map(el => ({
id: el.id,
className: el.className,
accept: el.accept,
outerHTML: el.outerHTML
}))
""",
"returnByValue": True
})
print(json.dumps(result.get("result", {}).get("value"), indent=2))
# Check for "Add source" buttons
print("\nSearching for 'Add source' text...")
result = execute_cdp_command(ws_url, "Runtime.evaluate", {
"expression": """
(function() {
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
const matches = [];
while(node = walker.nextNode()) {
if(node.textContent.includes('Add source') || node.textContent.includes('Upload')) {
matches.push({
text: node.textContent,
parentTag: node.parentElement.tagName,
parentClass: node.parentElement.className
});
}
}
return matches;
})()
""",
"returnByValue": True
})
print(json.dumps(result.get("result", {}).get("value"), indent=2))
if __name__ == "__main__":
inspect_dom()
|