tavikukko / Chrome-SP-Editor

Extension for creating and updating files (js, css) in SharePoint Online from Developer Tools
122 stars 39 forks source link

Cannot make a cache safe URL for " ~sitecollection/style library/folder1/folder2/jquery.min.js", file not found. Please verify that the file exists under the layouts directory. #4

Closed Gennady-G closed 7 years ago

Gennady-G commented 7 years ago

Hi!

Maybe I have done something wrong, but it breaks my test site collection page

Cannot make a cache safe URL for " ~sitecollection/style library/folder1/folder2/jquery.min.js", file not found. Please verify that the file exists under the layouts directory.

I used ~sitecollection alias and a space in "style library", maybe it is the mistake. However - how can I revert this change? I don't see this string neither in SPD seattle.master nor in Home.aspx

[SPException: Cannot make a cache safe URL for " ~sitecollection/style library/folder1/folder2/jquery.min.js", file not found. Please verify that the file exists under the layouts directory.]
   Microsoft.SharePoint.Utilities.SPUtility.MakeBrowserCacheSafeLayoutsUrl(String name, Boolean localizable, Int32 desiredVersion) +1436
   Microsoft.SharePoint.WebControls.ScriptLinkInfo.ToScriptUrl(Page page) +674
   Microsoft.SharePoint.WebControls.ScriptLinkInfo.ToScriptBlock(Page page) +23
   Microsoft.SharePoint.WebControls.ScriptLink.RenderScriptBlockInternal(Control ctrl, Page page, Boolean afterUI, HtmlTextWriter writer, Boolean deltaPage) +1219
   Microsoft.SharePoint.WebControls.ScriptLink.RenderScriptBlock(Control ctrl, Page page, HtmlTextWriter writer, Boolean afterUI) +56
   Microsoft.SharePoint.WebControls.ScriptLink.Render(HtmlTextWriter writer) +192
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +80
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +160
   System.Web.UI.HtmlControls.HtmlHead.RenderChildren(HtmlTextWriter writer) +27
   System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +47
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +80
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +160
   System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +47
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +80
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +160
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +80
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +160
   System.Web.UI.Page.Render(HtmlTextWriter writer) +39
   Microsoft.SharePoint.WebControls.DeltaPage.RenderToBase(HtmlTextWriter writer) +918
   Microsoft.SharePoint.WebControls.DeltaPage.Render(HtmlTextWriter writer) +81
   Microsoft.SharePoint.WebPartPages.WikiEditPage.Render(HtmlTextWriter writer) +218
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +80
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +8921

SP2013 with last CU(15.0.4875.1000), (maybe Publishing Features are On, cannot check now)

Tried to view all installed userCustomActions but see nothing (I drop this in CEWP on other site collection):

<label for="inputsitecollectionurl">Site Col url: </label>
<input type="text" id="inputsitecollectionurl" size="45"/>
<input type="button" id="buttonshowscriptlinks" value="Show Scriptlinks"/><br/>
<div id="message"></div><br />

<script type="text/javascript" language="javascript">
    "use strict";

    if (!window.console) window.console = {};
    if (!window.console.log) window.console.log = function () { };

    // add jquery from current site collection
    var url = _spPageContextInfo.siteAbsoluteUrl + "/Style%20Library/scripts/";
    document.write("<script src='" + url + "jquery-3.1.1.min.js'><\/script>");

   // output results
    function Write(s) {
        var txt = jQuery("#message").html();
        txt += s + "<br/>";

        jQuery("#message").html(txt);
    }

   // here try to find broken user script links:
    function showScriptLinks() {
        var siteColUrl = jQuery("#inputsitecollectionurl").val();

        var ctx = new SP.ClientContext(siteColUrl);
        var site = ctx.get_web();
        ctx.load(site);

        var userCustomActions = site.get_userCustomActions();
        ctx.load(userCustomActions);
        ctx.executeQueryAsync(onSuccess, onError);

        function onSuccess() {
            console.log("Success");
            console.log("Web name is: " + site.get_title());
            var result = userCustomActions.get_data();
            console.log(result);
            var len = result.length;
            Write("Custom Actions array length: " + len);

            if (len > 0) {
               // lenght is 0
            }
        }

        function onError(sender, args) {
            alert("Call failed. Error: " + args.get_message());
            console.log("Call failed. Error: " + args.get_message());
        }
    }

    function process() {
        try {
            jQuery("#inputsitecollectionurl").val("http://server/sites/siteColWithBrokenPage");
            jQuery("#buttonshowscriptlinks").on("click", function () {
                // try get broken user script links:
                showScriptLinks();
            });
        } catch (e) {
            console.log(e.name + ": " + e.message);
        }
    }

    ExecuteOrDelayUntilScriptLoaded(function () {
        process();
    }, "sp.js");
</script>

Best regards, Gennady

Gennady-G commented 7 years ago

Oh, my mistake. Closed.

I used get_web() instead of get_site()..

Used this code to remove broken scriplinks, thanks to Vadim Gremyachev post http://sharepoint.stackexchange.com/questions/164745/unable-to-unregister-usercustomactions-added-at-location-scriptlink-using-csom:

    function deleteCustomActionById(sequenceNo) {
        var siteColUrl = jQuery("#inputsitecollectionurl").val();
        var sequenceNumToDelete = parseInt(sequenceNo, 10);

        var ctx = new SP.ClientContext(siteColUrl);
        var site = ctx.get_site();
        ctx.load(site);

        var userCustomActions = site.get_userCustomActions();
        ctx.load(userCustomActions);
        ctx.executeQueryAsync(onSuccessGetCustomAction, onErrorGetCustomAction);

        function onSuccessGetCustomAction() {

            var result = userCustomActions.get_data().filter(function (a) {
                var seqNumber = a.get_sequence();

                if (a.get_sequence() === sequenceNumToDelete)
                    return a;
            });
            console.log(result);

            Write("Deleting Custom Actions with selected sequence..");

            if (result.length > 0) {
                result[0].deleteObject();
                ctx.executeQueryAsync(onSuccessDeleteCustomAction, onErroronDeleteCustomAction);
            }
  // ..
}
tavikukko commented 7 years ago

Hi, so you created scriptlink that broke your sitecollection? And you could not remove it from SP Editor extension?

Gennady-G commented 7 years ago

Hi, so you created scriptlink that broke your sitecollection?

Hi! Yes, I got an exception on all site pages and empty screen on Application pages.

And you could not remove it from SP Editor extension?

Yes, I didn't find how to remove it. Maybe I have not read documentation carefully and You allow to do it, I haven't realized..

I used code to remove it, now problem is resolved

tavikukko commented 7 years ago

Ok, good. The problem occurs when the MakeBrowserCacheSafeLayoutsUrl fails, then the entire page is broken. If the customaction scope was sitecollection, then the entire sitecollection will get this error. Chrome SP Editor needs _spPageContextInfo from the page and when this error ocurrs, the info in not in the page and it cannot remove the broken customaction. Maybe I could add validation of the url when adding the scriptlink. Will close this for now. Thanks for reporting!

Gennady-G commented 7 years ago

Hi tavikukko! Good idea! And thank You too! :)

Best regards,
Gennady