Forums before death by AOL, social media and spammers... "We can't have nice things"
|    alt.os.linux    |    Getting to be as bloated as Windows!    |    107,822 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 107,821 of 107,822    |
|    Maria Sophia to Maria Sophia    |
|    Re: =?utf-8?Q?Tutorial=3A_Firefox_right=    |
|    24 Feb 26 16:51:23    |
   
   XPost: alt.comp.software.firefox, alt.comp.os.windows-10   
   From: mariasophia@comprehension.com   
      
   Maria Sophia wrote:   
   > As far as I've been able to ascertain by testing, no GUI program will ever   
   > appear on a Windows desktop when launched from a Firefox native host on   
   > Windows, but, it should still work on Linux.   
      
   Voila!   
   Success at last!   
      
   The native host runs inside a restricted, non-interactive Windows session.   
   Unfortunately, we've learned that Windows-GUI programs apparently cannot   
   appear from that session, but file I/O works perfectly.   
      
   So the example file-based-change-detector below is a natural fit.   
      
   Once I stopped fighting that one immovable Windows-GUI wall, a whole   
   landscape of genuinely useful, practical, even elegant but non-GUI   
   possibilities open up for our first working Firefox extension.   
      
   Let's write a simple webpage-change detector instead.   
   It will tell us if a web page has Changed or NotChanged.   
      
   Overview:   
    a. We'll keep everything in the Firefox home directory, as before   
    C:\app\browser\firefox\openwithgvim\*.{js,bat,json,py,log,reg}   
    b. And create a subdirectory to watch if web pages have been changed.   
    C:\app\browser\firefox\openwithgvim\pagewatch\{report.txt,last.html}   
    c. Inside pagewatch, the Python host will maintain:   
    i. last.html, the last version of the page   
    ii. report.txt, the human-readable "changed / not changed" result   
    iii. (optional) snapshots/, if we ever want to archive versions   
   This keeps everything tidy and avoids clutter   
      
   The logic will be simple because this is to be an example extension.   
    A. If last.html does not exist:   
    Write the new HTML to last.html   
    Write a report saying: FIRST RUN - baseline saved   
    Return { ok: true, changed: true }   
    B. If last.html does exist:   
    Read it   
    Compare it to the new HTML (simple string comparison)   
    C. If identical:   
    Write: NO CHANGE   
    Return { ok: true, changed: false }   
    D. If different:   
    Write:   
    CHANGED   
    Old length: ####   
    New length: ####   
    Timestamp: ...   
    Overwrite last.html with the new HTML   
    Return { ok: true, changed: true }   
    E. In testing, I had to add code to overcome file locks gracefully.   
      
   Here is every step of the test procedure:   
   1. Start Firefox   
   2. Click your bookmark for about:debugging#/runtime/this-firefox   
   3. Click "Load Temporary Add-on..."   
   4. Select C:\app\browser\firefox\openwithgvim\manifest.json   
   5. Open a local file file:///C:/data/amazon/vine/vine.htm   
   6. Rightclick in white space on that local file   
   7. Select "Open page source in gVim" (we never changed it)   
   8. Check the pagewatch report file for status   
    C:\> type C:\app\browser\firefox\openwithgvim\pagewatch\report.txt   
    NO CHANGE   
    URL: file:///C:/data/amazon/vine/vine.htm   
    Timestamp: 2026-02-24 16:34:02   
    Length: 53565 bytes   
   9. Edit the source (Control+U or rightclick > View page source   
    Change something & refresh the page   
    Note that ViewPageSource is an edit due to these settings:   
    about:config > view_source.editor   
    view_source.editor.external = true   
    view_source.editor.path = C:\app\editor\txt\vi\gvim.exe   
   10. Check the pagewatch report file for status   
    C:\> type C:\app\browser\firefox\openwithgvim\pagewatch\report.txt   
    CHANGED   
    URL: file:///C:/data/sys/apppath/vistuff/vine.htm   
    Timestamp: 2026-02-24 16:39:30   
    Old length: 53565 bytes   
    New length: 53541 bytes   
      
   The only file that changed was the python native messaging host script.   
    =====< cut below for gvim_host.py >=====   
    import sys   
    import struct   
    import json   
    import os   
    from datetime import datetime   
      
    # Base directory for everything   
    BASE_DIR = r"C:\app\browser\firefox\openwithgvim"   
    WATCH_DIR = os.path.join(BASE_DIR, "pagewatch")   
      
    LAST_FILE = os.path.join(WATCH_DIR, "last.html")   
    REPORT_FILE = os.path.join(WATCH_DIR, "report.txt")   
      
    DEBUG_LOG = os.path.join(BASE_DIR, "host_debug.log")   
    ERR_LOG = os.path.join(BASE_DIR, "host_stderr.log")   
      
      
    def log(msg):   
    """Write debug messages to stderr log, but never crash if the file is   
   locked."""   
    try:   
    with open(ERR_LOG, "a", encoding="utf-8") as f:   
    f.write(str(msg) + "\n")   
    except Exception:   
    # Windows sometimes locks files; logging must never kill the host   
    pass   
      
      
    def ensure_directories():   
    """Create the pagewatch directory if missing."""   
    if not os.path.exists(WATCH_DIR):   
    os.makedirs(WATCH_DIR, exist_ok=True)   
      
      
    def read_message():   
    """Read a native message from Firefox."""   
    raw_length = sys.stdin.buffer.read(4)   
    if not raw_length:   
    log("No length header, stdin closed")   
    return None   
      
    length = struct.unpack("
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca