Safeapp property on window when using localhost

safe-browser
api

#1

I am trying to follow the directions from here using mock routing but I am having some difficulty getting started. I definitely have beaker working with mock routing but I am not getting window.safeApp injected when using localhost. Here are the steps

  • make a folder, cd into that folder
  • put index.html (below) in
  • run python3 -m http.server 8000 --bind 127.0.0.1 or equivalent
  • visit localhost://p:8000/ in mock routing beaker browser
  • see the wtf alert

Any help would be appreciated, just trying to get started with hello world here

<html>
<head>
<title>dumb</title>
</head>
<body>
    stupid simple safe network

<script>
    if (typeof(window.safeApp) == "undefined")
        alert('wtf?')
    // alert('hi')
    window.safeApp.initialise({
        id: 'myid',
        name: 'myname',
        vendor: 'me'
    }, (newState) => {
        console.log("Network state changed to: ", newState);
    })
    .then((appHandle) => {
        console.log('SAFEApp instance initialised and handle returned: ', appHandle);
    });
</script>
</body>

</html>

js code is from docs


#2

Ok nevermind. This works, the issue is that my console.log statements aren’t showing up which made me think the code wasn’t working. I change the code to this for now, will change log function later

<html>
<head>
<title>dumb</title>
</head>
<body>
    stupid simple safe networkx
    <pre id="out"></pre>
<script>
    out = document.getElementById('out')

    log = function(thing) { out.innerHTML += thing +'\n'}

    if (typeof(window.safeApp) == "undefined")
        log('safe network api not injected.')
    else
        log('safe network api injected.')

    // alert('hi')
    window.safeApp.initialise({
        id: 'myid',
        name: 'myname',
        vendor: 'me'
    }, (newState) => {
        log("Network state changed to: " + newState);
    })
    .then((appHandle) => {
        log('SAFEApp instance initialised and handle returned: ' + appHandle);
    });
</script>
</body>

</html>

#3

This topic was automatically closed after 60 days. New replies are no longer allowed.