简体   繁体   中英

How do I use the tabs API?

I am creating a program that needs to interact with other tabs on the window that the HTML file is opened on, and I found this code. However, I think that I have implemented it incorrectly as it does nothing. Here is my (incomplete) code:

HTML:

<html lang="en">

<head>

    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Workench</title>

    <script src="dependencies/index.js"></script>
    <link rel="stylesheet" href="dependencies/index.css">

</head>

<body>

    <nav id="toolbar">

        <div id="file">

            <label>File</label>

            <br>

            <button onclick="toolbar.file.saveDoc()">Save</button>
            <button onclick="toolbar.file.newDoc()">New</button>
            <button onclick="toolbar.file.loadDoc()">Load</button>

        </div>

        <div id="upload">

            <label>Upload</label>

            <br>

            <button onclick="toolbar.upload.seasaw()">Seasaw</button>
            <button onclick="toolbar.upload.googleClassroom()">Google Classroom</button>

        </div>

    </nav>

</body>

JavaScript:

import "browser";

const toolbar = {

    file : {

        saveDoc () {

            browser.tabs.create({url: "docs.google.com"}).then(() => {
                browser.tabs.executeScript({
                  code: "console.log('hello');"
                });
              });

        },

        newDoc () {

            

        },

        loadDoc() {

            

        }

    }

};

Any help would be appreciated: :)

For context, this is for my school. It needs to essentially be a text editor that then automatically uploads the text to the platforms that my school uses.

The problem is that docs.google.com has not provided you permission for this, see the page you have shared

在此处输入图像描述

You will need to make sure you have host permissions for the URLs you intend to interact with.

I advise you to first try this with pages of the same domain opened in a new tab and when that works, you may venture into the usage with different domains.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM