Is this correct to use image fill

function createThemePreview(selection) {
    const rect = new Rectangle();
    rect.name = "themePreview";
    rect.width = 866;
    rect.height = 537;
    rect.cornerRadii = {
        topLeft: 0,
        topRight: 0,
        bottomLeft: 0,
        bottomRight: 0,
    };
    rect.fill = new Color("#000000");
    rect.stroke = new Color("#707070");
    rect.strokeWidth = 1;
    rect.moveInParentCoordinates(0, 156);
    var imagefill;
    imageFill().then(
        (success => {
            console.log("image fill success");
            console.log(success);
            imagefill = success;
        }),
        (failure => {
            console.log("image fill failed");
        })
    );
    rect.fill = imagefill;
    selection.insertionParent.addChild(rect);
    return rect;
}

Throws Error

Plugin Error: Plugin 07b2dfeb is not permitted to make changes from the background. Return a Promise to continue execution asynchronously.
        at convertPluginErrorToString (plugins/PluginErrorUtil.js:1:198)
        at internalFormatPluginError (plugins/PluginErrorUtil.js:1:503)
        at internalReportPluginError (plugins/PluginErrorUtil.js:1:610)
        at Object.reportPluginError (plugins/PluginErrorUtil.js:1:1015)
        at Object.checkAllowedToEdit (plugins/ScenegraphGuard.js:1:1094)
        at Rectangle.<anonymous> (plugins/ScenegraphWrappers.js:1:2286)
        at createThemePreview (C:\Users\PramUkesh\AppData\Local\Packages\Adobe.CC.XD_adky2gkssdxte\LocalState\develop\07b2dfeb\main.js:334:15)